Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Setting a configuration property from Java
Setting a configuration property from Java [message #1235519] Fri, 24 January 2014 15:11 Go to next message
nicholas pacini is currently offline nicholas paciniFriend
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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
Re: Setting a configuration property from Java [message #1236447 is a reply to message #1235527] Mon, 27 January 2014 08:40 Go to previous messageGo to next message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
Hello Ed,

thanks for your reply, sure i see your point.

but before trying to provide a usable repro, please allow me to ask some generic question (to you and/or anyone else):

first of all, is it possible to set a configuration property from java code?
then, if so, are there some examples or tutorials which explain how to do it? because i can't seem to find any

thanks for your time,

Regards,
Nicholas


Re: Setting a configuration property from Java [message #1236519 is a reply to message #1235519] Mon, 27 January 2014 12:07 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Hi

It is possible. Have a look at the classes TransformationExecutor and ExecutionContextImpl.
Re: Setting a configuration property from Java [message #1236846 is a reply to message #1236519] Tue, 28 January 2014 07:57 Go to previous message
nicholas pacini is currently offline nicholas paciniFriend
Messages: 31
Registered: December 2010
Member
Hi Christopher,

thanks for the advice, I've always used different classes to launch the transformations, so i had to re-write almost everything but now it works!

thanks again,
Nicholas
Previous Topic:Transforming two model instances into a single model instance
Next Topic:Stereotype not applied to the xmi output file !
Goto Forum:
  


Current Time: Thu Apr 25 19:20:13 GMT 2024

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

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

Back to the top