Home » Modeling » QVT-OML » Setting a configuration property from Java
Setting a configuration property from Java [message #1235519] |
Fri, 24 January 2014 15:11 |
nicholas pacini Messages: 31 Registered: December 2010 |
Member |
|
|
Hello everyone,
I'm writing a Operational QVT which will use a "configuration property"
In Eclipse's run Configuration for the transformation i can see my configuration property and i can set the value as expected.
Now i'm stuck trying to find a way to set this configuration property from Java, since i need to call the transformation from Java code.
I'm showing you my attempt, hoping that it's enough clear. I've reused an already available (and working) code:
private static void launchTransformation(String trURI, String trName,
boolean generateTrace, Resource chessModel, Resource feiModel, IProgressMonitor monitor) throws Exception{
String chessModelURIString = chessModel.getURI().toString();
String feiModelURIString = feiModel.getURI().toString();
String qvtTraceURIString = generateTrace ? chessModelURIString.substring(0,
chessModelURIString.lastIndexOf('.') + 1) + "qvtotrace" : null;
String trURIString = trURI;
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType c = manager
.getLaunchConfigurationType(QvtLaunchConfigurationDelegate.LAUNCH_CONFIGURATION_TYPE_ID);
ILaunchConfigurationWorkingCopy instance = c.newInstance(null, trName);
instance.setAttribute(IQvtLaunchConstants.CLEAR_CONTENTS + "1", true);
instance.setAttribute(IQvtLaunchConstants.CLEAR_CONTENTS + "2", true);
instance.setAttribute(IQvtLaunchConstants.ELEM_COUNT, 2);
instance.setAttribute(IQvtLaunchConstants.FEATURE_NAME + "1", "");
instance.setAttribute(IQvtLaunchConstants.FEATURE_NAME + "2", "");
instance.setAttribute(IQvtLaunchConstants.MODULE, trURIString);
instance.setAttribute(IQvtLaunchConstants.TARGET_MODEL + "1", chessModelURIString);
instance.setAttribute(IQvtLaunchConstants.TARGET_TYPE + "1", "NEW_MODEL");
instance.setAttribute(IQvtLaunchConstants.TARGET_MODEL + "2", feiModelURIString);
instance.setAttribute(IQvtLaunchConstants.TARGET_TYPE + "2", "NEW_MODEL");
if (generateTrace){
instance.setAttribute(IQvtLaunchConstants.TRACE_FILE, qvtTraceURIString);
instance.setAttribute(IQvtLaunchConstants.USE_TRACE_FILE, generateTrace);
}
QvtTransformation qvtTransformation = new QvtInterpretedTransformation(
QvtLaunchConfigurationDelegateBase.getQvtModule(instance));
IStatus status = QvtLaunchConfigurationDelegateBase.validate(
qvtTransformation, instance);
if (status.getSeverity() > IStatus.WARNING) {
throw new CoreException(status);
}
EvaluationMonitor execMonitor = createMonitor();
Context context = QvtLaunchUtil.createContext(instance);
OutputStreamWriter s = new OutputStreamWriter(CHESSProjectSupport.CHESS_CONSOLE);
context.setLog(new WriterLog(s));
context.setMonitor(execMonitor);
//begin attempt
Map<String, String> configMap = new HashMap<String, String>();
Set<QvtConfigurationProperty> configProps = qvtTransformation.getConfigurationProperties();
for (QvtConfigurationProperty qvtConfProp : configProps) {
if(qvtConfProp.getName().equals("systemName")){
configMap.put(qvtConfProp.getName(), "attempt");
/**
* "attempt" will be a String selected by a user through a dialog
* at run-time passed as parameter to this function
*/
}
}
instance.setAttribute(IQvtLaunchConstants.CONFIGURATION_PROPERTIES, configMap);
//end attempt
QvtLaunchConfigurationDelegateBase.doLaunch(qvtTransformation,instance, context);
qvtTransformation.cleanup();
}
unfortunately the configuration property called "systemName" is null when i read it in the transformation.
I know i'm asking a lot, but it would be great if someone notices something wrong or missing in my attempt and could point it to me.
If you need further information, please tell me.
I apologize in advance if it has been already discussed, but i haven't found anything
Regards,
Nicholas
|
|
|
Re: Setting a configuration property from Java [message #1235527 is a reply to message #1235519] |
Fri, 24 January 2014 15:37 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
You can study the code just as well as I can. Or you can use a debugger
to conmopare what works.
But you're more likely to get takers if you provide a useable repro. See
http://wiki.eclipse.org/OCL/ForumNetiquette
Regards
Ed Willink
On 24/01/2014 15:11, nicholas pacini wrote:
> Hello everyone,
>
> I'm writing a Operational QVT which will use a "configuration property"
> In Eclipse's run Configuration for the transformation i can see my
> configuration property and i can set the value as expected.
>
> Now i'm stuck trying to find a way to set this configuration property
> from Java, since i need to call the transformation from Java code.
>
> I'm showing you my attempt, hoping that it's enough clear. I've reused
> an already available (and working) code:
>
> private static void launchTransformation(String trURI, String trName,
> boolean generateTrace, Resource chessModel, Resource
> feiModel, IProgressMonitor monitor) throws Exception{
>
> String chessModelURIString = chessModel.getURI().toString();
>
> String feiModelURIString = feiModel.getURI().toString();
>
> String qvtTraceURIString = generateTrace ?
> chessModelURIString.substring(0,
> chessModelURIString.lastIndexOf('.') + 1) +
> "qvtotrace" : null;
>
> String trURIString = trURI;
>
> ILaunchManager manager =
> DebugPlugin.getDefault().getLaunchManager();
> ILaunchConfigurationType c = manager
> .getLaunchConfigurationType(QvtLaunchConfigurationDelegate.LAUNCH_CONFIGURATION_TYPE_ID);
> ILaunchConfigurationWorkingCopy instance = c.newInstance(null,
> trName);
>
> instance.setAttribute(IQvtLaunchConstants.CLEAR_CONTENTS +
> "1", true);
> instance.setAttribute(IQvtLaunchConstants.CLEAR_CONTENTS +
> "2", true);
> instance.setAttribute(IQvtLaunchConstants.ELEM_COUNT, 2);
> instance.setAttribute(IQvtLaunchConstants.FEATURE_NAME + "1",
> "");
> instance.setAttribute(IQvtLaunchConstants.FEATURE_NAME + "2",
> "");
> instance.setAttribute(IQvtLaunchConstants.MODULE, trURIString);
> instance.setAttribute(IQvtLaunchConstants.TARGET_MODEL + "1",
> chessModelURIString);
> instance.setAttribute(IQvtLaunchConstants.TARGET_TYPE + "1",
> "NEW_MODEL");
> instance.setAttribute(IQvtLaunchConstants.TARGET_MODEL + "2",
> feiModelURIString);
> instance.setAttribute(IQvtLaunchConstants.TARGET_TYPE + "2",
> "NEW_MODEL");
>
> if (generateTrace){
> instance.setAttribute(IQvtLaunchConstants.TRACE_FILE,
> qvtTraceURIString);
> instance.setAttribute(IQvtLaunchConstants.USE_TRACE_FILE, generateTrace);
> }
>
> QvtTransformation qvtTransformation = new
> QvtInterpretedTransformation(
> QvtLaunchConfigurationDelegateBase.getQvtModule(instance));
>
> IStatus status = QvtLaunchConfigurationDelegateBase.validate(
> qvtTransformation, instance);
>
> if (status.getSeverity() > IStatus.WARNING) {
> throw new CoreException(status);
> }
>
> EvaluationMonitor execMonitor = createMonitor();
> Context context = QvtLaunchUtil.createContext(instance);
>
> OutputStreamWriter s = new
> OutputStreamWriter(CHESSProjectSupport.CHESS_CONSOLE);
> context.setLog(new WriterLog(s));
> context.setMonitor(execMonitor);
> //begin attempt
> Map<String, String> configMap = new HashMap<String, String>();
> Set<QvtConfigurationProperty> configProps =
> qvtTransformation.getConfigurationProperties();
> for (QvtConfigurationProperty qvtConfProp : configProps) {
> if(qvtConfProp.getName().equals("systemName")){
> configMap.put(qvtConfProp.getName(), "attempt");
> /**
> * "attempt" will be a String selected by a user
> through a dialog * at run-time passed as parameter to
> this function
> */
> }
> }
> instance.setAttribute(IQvtLaunchConstants.CONFIGURATION_PROPERTIES,
> configMap);
> //end attempt
> QvtLaunchConfigurationDelegateBase.doLaunch(qvtTransformation,instance, context);
>
> qvtTransformation.cleanup();
> }
>
> unfortunately the configuration property called "systemName" is null
> when i read it in the transformation.
>
> I know i'm asking a lot, but it would be great if someone notices
> something wrong or missing in my attempt and could point it to me.
> If you need further information, please tell me.
>
> I apologize in advance if it has been already discussed, but i haven't
> found anything
>
> Regards,
> Nicholas
|
|
| | | |
Goto Forum:
Current Time: Tue Sep 24 22:39:51 GMT 2024
Powered by FUDForum. Page generated in 0.03320 seconds
|