Calling Java Code from QVTO 1.0.1 [message #479644] |
Tue, 11 August 2009 16:29  |
Eclipse User |
|
|
|
hello,
I am trying to call a java custom library from qvto.I followed the
instructions described in the following post :
http://dev.eclipse.org/newslists/news.eclipse.modeling.m2m/m sg02375.html
Here is the steps i followed.
1. Created a plug-in with the java class which contain a public method
that i want to call from qvt
2. added the following metainfo method.
The function that i want to call from QVT has the following signature.
OclAny::getJP(String): Set(OclAny)
=============================
public static class Metainfo {
private static final String[] Get_JP = new String[] {
"OclAny", "String", "Set(OclAny)" };
public static String[] getJP(Object self,String oclExp)
{
return Get_JP;
}
}
=============================
3. Created an extention point in the plugin.xml file for
"org.eclipse.m2m.qvt.oml.ocl.emf.libraries" .and the metamodel set to UML
Here is a copy of the plugin.xml file:
=============================
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.m2m.qvt.oml.ocl.emf.libraries">
<library class="CheckOCLConstraint.getJP" id="CheckOCLConstraint.getJP">
<inMetamodel uri="http://www.eclipse.org/uml2/2.1.0/UML"/>
</library>
</extension>
</plugin>
=============================
However in the file it gives an error [unknown extension point
"org.eclipse.m2m.qvt.oml.ocl.emf.libraries"].
But i tried to ignore the error and export the plugin anyway.
4. exported the plug-in and deployed it .
5. from qvto code when i try to import the library it gives an error:
[cannot find imported module].
=============================
modeltype UML uses "http://www.eclipse.org/uml2/2.1.0/UML";
transformation Class(in a:UML,in b:UML,inout c:UML);
import CheckOCLConstraint.getJP;
=============================
Can someone please tell me how to fix this.
|
|
|
|
|
Re: Calling Java Code from QVTO 1.0.1 [message #479798 is a reply to message #479698] |
Wed, 12 August 2009 10:31   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------040006040804040103080806
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Hi mary ,
You are using quite old version of QVTo. I advise you to switch on
recent 2.0.0 version (see
http://www.eclipse.org/modeling/m2m/downloads/index.php?proj ect=qvtoml).
It has many improvements over 1.0.1 also in area of black-box supporting.
Some replies in-line, below.
Regards,
Sergey
mary wrote:
>> 3. Created an extention point in the plugin.xml file for
>> "org.eclipse.m2m.qvt.oml.ocl.emf.libraries" .and the metamodel set to
>> UML Here is a copy of the plugin.xml file:
>> =============================
>> <?xml version="1.0" encoding="UTF-8"?>
>> <?eclipse version="3.4"?>
>> <plugin>
>> <extension point="org.eclipse.m2m.qvt.oml.ocl.emf.libraries">
>> <library class="CheckOCLConstraint.getJP"
>> id="CheckOCLConstraint.getJP">
>> <inMetamodel uri="http://www.eclipse.org/uml2/2.1.0/UML"/> </library>
>> </extension>
>> </plugin>
>> =============================
>> However in the file it gives an error [unknown extension point
>> "org.eclipse.m2m.qvt.oml.ocl.emf.libraries"]. But i tried to ignore
>> the error and export the plugin anyway.
>
>
> For the extention point i solved the error.. instead of
> having["org.eclipse.m2m.qvt.oml.ocl.emf.libraries"] I put
> [org.eclipse.m2m.qvt.oml.ocl.libraries] and the error is gone.
> However, still I cant access the library from qvt transformation..The
> error is still [can not find imported module]
It was mistake in earlier post. You're right, ext.point should be
"org.eclipse.m2m.qvt.oml.ocl.libraries".
Looking at posted library's registration in plugin.xml
<library class="CheckOCLConstraint.getJP" id="CheckOCLConstraint.getJP">
I can figure out that library class is named 'getJP' and it's located in
java package 'CheckOCLConstraint'. I think it's not true :)
You should specify fully qualified java class for 'class=' property.
I've attached java library sample (taken from
'org.eclipse.m2m.tests.qvt.oml' plug-in).
In plugin.xml it's registered as follows:
<extension point="org.eclipse.m2m.qvt.oml.ocl.libraries">
<library
class="org.eclipse.m2m.tests.qvt.oml.TestBlackboxLibrary"
id="TestBlackboxLibrary">
<inMetamodel uri="http://www.eclipse.org/emf/2002/Ecore"/>
<outMetamodel uri="http://www.eclipse.org/emf/2002/Ecore"/>
</library>
</extension>
Given it deployed the following script can test it:
import TestBlackboxLibrary;
modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
transformation testOldLib();
main() {
var v := object EClass{}.oclAnyMyOperation();
}
>
> I 've looked in the web and tried a lot of examples. Like the
> SampleLibrary example but yet it didn't work too..
> I don't know what am I missing!! Any help Plz?
>
> Thanks..
>
--------------040006040804040103080806
Content-Type: text/plain;
name="TestBlackboxLibrary.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="TestBlackboxLibrary.java"
/*********************************************************** ********************
* Copyright (c) 2008 Borland Software Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Borland Software Corporation - initial API and implementation
************************************************************ *******************/
package org.eclipse.m2m.tests.qvt.oml;
import java.util.Collections;
import java.util.Set;
import org.eclipse.emf.ecore.ENamedElement;
public class TestBlackboxLibrary {
public Set<ENamedElement> asRenamedSetSingleton(Object self, String newName) {
if(self instanceof ENamedElement) {
ENamedElement namedElement = (ENamedElement) self;
namedElement.setName(newName);
return Collections.singleton(namedElement);
}
return Collections.emptySet();
}
public final Set<Object> oclAnyMyOperation(Object self) {
return Collections.singleton(self);
}
/**
* Metainfo for the native methods should be accessible throu the static
* methods of inner class <code>Metainfo</code> with the same signature
* ant <code>String[]</code> return type. Returned array should contains
* string representation of OCL classifiers:
*
* array[0] - Context classifier
* array[n] - Classifier corresponds to the n-th operation parameter
* array[n+1] - Return type classifier
*/
public static class Metainfo {
private static final String[] RENAMED_SET_SINGLETON = new String[] {
"oclstdlib::OclVoid", // Void context -> module owned (context-less) operation
// imported library module is the implicit source object of the call
"oclstdlib::OclAny", // your argument1
"oclstdlib::String", // your argument2
"Set(ecore::ENamedElement)" // return type
};
private static final String[] OCLANY_MYOPERATION = new String[] {
"oclstdlib::OclAny",
"Set(oclstdlib::OclAny)"
};
public static final String[] asRenamedSetSingleton(Object arg, String newName) {
return RENAMED_SET_SINGLETON;
}
public static final String[] oclAnyMyOperation(Object arg) {
return OCLANY_MYOPERATION;
}
}
}
--------------040006040804040103080806--
|
|
|
|
|
Re: Calling Java Code from QVTO 1.0.1 [message #479881 is a reply to message #479877] |
Wed, 12 August 2009 17:26  |
Eclipse User |
|
|
|
Hi mary ,
Sure send me your library project. I'll check it.
Regards,
Sergey
mary wrote:
> Hello Sergey,
>
> Thanks a lot for your help. I tried to update to a newer version of QVT
> but couldn't as the newer version require eclipse V.3.5 and I am using
> RSA which is based on eclipse 3.4 . So unfortunately upgrading to qvt
> v.2 would be difficult. :(
>
> Please see comments in-line..
>
> Regards,
>
>
>> Looking at posted library's registration in plugin.xml
>
>> <library class="CheckOCLConstraint.getJP"
>> id="CheckOCLConstraint.getJP">
>
>> I can figure out that library class is named 'getJP' and it's located
>> in java package 'CheckOCLConstraint'. I think it's not true :)
>> You should specify fully qualified java class for 'class=' property.
>
> Actually it was true. This was the fully qualified java class name. :(
>
>> I've attached java library sample (taken from
>> 'org.eclipse.m2m.tests.qvt.oml' plug-in).
>> In plugin.xml it's registered as follows:
>> <extension point="org.eclipse.m2m.qvt.oml.ocl.libraries">
>> <library
>> class="org.eclipse.m2m.tests.qvt.oml.TestBlackboxLibrary"
>> id="TestBlackboxLibrary">
>> <inMetamodel uri="http://www.eclipse.org/emf/2002/Ecore"/>
>> <outMetamodel uri="http://www.eclipse.org/emf/2002/Ecore"/>
>> </library>
>> </extension>
>
>> Given it deployed the following script can test it:
>
>> import TestBlackboxLibrary;
>> modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
>> transformation testOldLib();
>> main() {
>> var v := object EClass{}.oclAnyMyOperation();
>> }
>
> I tried the library sample you sent and it worked from qvt and i had
> access to it. Unfortunately, for my library still cant import it from qvt.
> Can I send you my java plug-in project for you to see it and try
> importing it from qvt? If thats Ok with you i will really appreciate it,
> and BTW I have your email address..
>
> Thanks Again..
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.36750 seconds