Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Transform OCL into PL/SQL
Transform OCL into PL/SQL [message #1067141] Sat, 06 July 2013 10:25 Go to next message
Jérôme Brügger is currently offline Jérôme BrüggerFriend
Messages: 5
Registered: July 2013
Junior Member
Hello,

We are currently working for transforming OCL code into PL-SQL's triggers and stored procedures. We have a UML program (Visual Paradigm) that we transforming into XSD for creating an EMF metamodel. All the OCL code are stored into text files. Finally we can use MDT-OCL for the creation but we havn't find a way to have all the parsed tree. Per exemple :

context NAME
inv: role1.role2 = role3.role4

Will give :

  • role1.role2.=(role3.role4) (expression : Boolean)
  • self.role1.role2 (expression : CLASSNAME)
  • self.role1 (expression : CLASSNAME)
  • self (expression : CLASSNAME)
  • self.role3.role4 (expression : CLASSNAME)
  • self.role3 (expression : CLASSNAME)
  • self (expression : CLASSNAME)

But we havn't find the way to return the "=" part with the API and without, per exemple, using Regual Expression. Is there any way to return only this part with the TreeIterator from each Constraint ?

And a second thing, that is not important but perhaps someone can help us on this case too : we have parsed the EObject to String for the parsing of the expression part. Is there any getter for doing this one ?

For those two case, we have do a lot of research with the API, but we havn't find anything. I remain at your disposal if you need more information.

Best regards,
J.Brügger
Re: Transform OCL into PL/SQL [message #1067229 is a reply to message #1067141] Sun, 07 July 2013 19:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I expect the answer is probably yes, but I don't really understand what
you are asking.

Unfortunately your prepositions are incorrect and so ambiguous:

e.g. "All the OCL code are stored into text files"

means

? All the OCL code is read from text files
? All the OCL code is written to text files

Your will give result is your proprietary format that you don't explain.

Regards

Ed Willink






On 06/07/2013 18:07, Jérôme Brügger wrote:
> Hello,
>
> We are currently working for transforming OCL code into PL-SQL's
> triggers and stored procedures. We have a UML program (Visual
> Paradigm) that we transforming into XSD for creating an EMF metamodel.
> All the OCL code are stored into text files. Finally we can use
> MDT-OCL for the creation but we havn't find a way to have all the
> parsed tree. Per exemple :
>
> context NAME
> inv: role1.role2 = role3.role4
>
> Will give :
>
> role1.role2.=(role3.role4) (expression : Boolean)
> self.role1.role2 (expression : CLASSNAME)
> self.role1 (expression : CLASSNAME)
> self (expression : CLASSNAME)
> self.role3.role4 (expression : CLASSNAME)
> self.role3 (expression : CLASSNAME)
> self (expression : CLASSNAME)
>
> But we havn't find the way to return the "=" part with the API and
> without, per exemple, using Regual Expression. Is there any way to
> return only this part with the TreeIterator from each Constraint ?
>
> And a second thing, that is not important but perhaps someone can help
> us on this case too : we have parsed the EObject to String for the
> parsing of the expression part. Is there any getter for doing this one ?
>
> For those two case, we have do a lot of research with the API, but we
> havn't find anything. I remain at your disposal if you need more
> information.
>
> Best regards,
> J.Brügger
Re: Transform OCL into PL/SQL [message #1067237 is a reply to message #1067229] Sun, 07 July 2013 20:45 Go to previous messageGo to next message
Jérôme Brügger is currently offline Jérôme BrüggerFriend
Messages: 5
Registered: July 2013
Junior Member
Hello,

Oh yes excuse-me. When we exporting the metamodel to EMF, instead of keeping the OCL codes inside it, we exporting all those ones into text files. After we have used this documentation : http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FParsingDocuments.html&cp=49_5_2. So this is reading from text.

And we have used this piece of code :
{ReturnType} body = next.getSpecification()

The result from EMF is :

0 -> role1.role2.=(role3.role4)
1 -> EObject (expression : Boolean)
2 -> self.role1
3 -> EObject (expression : CLASSNAME)
...

And we have just created a hashMap and inserted even lines into keys and odd lines into values.

If you need more information or the code that has been used, I remain at your disposal.

Best regards and thank you for your help,
J.Brügger
Re: Transform OCL into PL/SQL [message #1067336 is a reply to message #1067237] Mon, 08 July 2013 10:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I'm sorry, but you seem to assume that I know what you are doing.

You need to be much clearer about what your steps are, where OCL fits in
and what you observe.

In particular "The result from EMF is : "

gives me no clue as to what model you are printing how, why or where.

Regards

Ed Willink




On 07/07/2013 21:45, Jérôme Brügger wrote:
> Hello,
>
> Oh yes excuse-me. When we exporting the metamodel to EMF, instead of
> keeping the OCL codes inside it, we exporting all those ones into text
> files. After we have used this documentation :
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FParsingDocuments.html&cp=49_5_2.
> So this is reading from text.
>
> And we have used this piece of code :
> {ReturnType} body = next.getSpecification()
> The result from EMF is :
>
> 0 -> role1.role2.=(role3.role4)
> 1 -> EObject (expression : Boolean)
> 2 -> self.role1
> 3 -> EObject (expression : CLASSNAME)
> ...
>
> And we have just created a hashMap and inserted even lines into keys
> and odd lines into values.
>
> If you need more information or the code that has been used, I remain
> at your disposal.
>
> Best regards and thank you for your help,
> J.Brügger
Re: Transform OCL into PL/SQL [message #1074487 is a reply to message #1067336] Fri, 26 July 2013 23:14 Go to previous messageGo to next message
Jérôme Brügger is currently offline Jérôme BrüggerFriend
Messages: 5
Registered: July 2013
Junior Member
Hello,

Excuse me for the late response and the unclarity of my message. It think it will be better if I insert the part of the code that I use and explain my problem :

EPackage.Registry registry = new EPackageRegistryImpl();
registry.put(Projet01Package.eNS_URI, Projet01Package.eINSTANCE);

EcoreEnvironmentFactory environmentFactory = new EcoreEnvironmentFactory(registry);
OCL ocl = OCL.newInstance(environmentFactory);

File file = new File("C:/Users/jerome/workspace/OCLToPLSQL/model/projet01.ocl");
InputStream in = new FileInputStream(file);

Map<String, Constraint> constraintMap = new HashMap<String, Constraint>();

try {
	
	OCLInput document = new OCLInput(in);
	
	List<Constraint> constraints = ocl.parse(document);
	
	Integer numberConstraint = 0;
	
	for (Constraint next : constraints) {
		
		if(next.getStereotype().toString() == "invariant")
		{
			
			String actualContext = contexteWithoutSelf(next.getSpecification().getContextVariable().toString());
			
			constraintMap.put(next.getName(), next);
			
			Iterator<EObject> body = next.getSpecification().eAllContents();
			
			Map mapSpecsFromTreeIte = new HashMap();
			
			Integer numberMapSpecsFromTreeIterator = 0;
			
			String globalconstraint = next.getSpecification().getBodyExpression().toString();
			
			Boolean isSimpleCycleConstraint = globalconstraint.matches("^self\\.([a-z]+\\.){2}=\\(self\\.[a-z]+\\.[a-z]+\\)$");
			
			Boolean isComplexConstraint = globalconstraint.matches("^(([a-z]+\\.){3}=\\([a-z]+\\.[a-z]+\\))|(([a-z]+\\.){2}=\\(([a-z]+\\.){2}[a-z]+\\))|(([a-z]+\\.){3,}=\\(([a-z]+\\.){2,}[a-z]+\\))$");
			
			if(isSimpleCycleConstraint == true) {
				
				String specsFromTreeIteValueTemp = null;
				
				Integer numberParsedConstraint = 0;
				
				while(body.hasNext()) {
					
					String containBodyConstraint = body.next().toString();

					Boolean regExForValideConstraint = BodyConstraintSelfOnly(containBodyConstraint);
					
					if (regExForValideConstraint == true) {
					
						if (numberMapSpecsFromTreeIterator % 2 == 0) {
							
							specsFromTreeIteValueTemp = containBodyConstraint;
							
						}
						else {

							String[] entityWithoutObject = containBodyConstraint.split("\\(expression: ");
							
							String mapSpecsFromTreeIteKey = entityWithoutObject[1].substring(0, entityWithoutObject[1].length()-1);
							
							if (!mapSpecsFromTreeIteKey.equals("Boolean")) {
								
								if (!mapSpecsFromTreeIteKey.equals(actualContext)) {
									
									mapSpecsFromTreeIte.put(numberParsedConstraint, new ParsedConstraint(numberConstraint, actualContext, parsedConstraintWithoutSelf(specsFromTreeIteValueTemp), mapSpecsFromTreeIteKey));
									numberParsedConstraint++;
									
								}
							}
						
						}
					
					}
					
					numberMapSpecsFromTreeIterator++;
					
				}


(This is a prototype). So first, I load the metamodel and load OCL constraints from a file. After I just do some checks to restrict the transformation to some specifics pattern (cycle constraints). Just after, I do something that I think that is not so good and I need help for this case : I iterate through "Iterator<EObject> body" but use an even/odd condition and even with that I cannot retrieve the top of the AST (with other aberrations that I could not avoid). There's somthing like a vistor pattern but I havn't understand if that feet that case too. Per exemple, this code will give the return that I wrote before. I hope that someone could help us on this case.

Best regards,
J.Brügger
Re: Transform OCL into PL/SQL [message #1074588 is a reply to message #1074487] Sat, 27 July 2013 06:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You can use eContainer() to climb to the root of the AST if that is what
you mean by the top.

next.getStereotype().toString() == "invariant"

is really smelly. Never use == for indepenedent Objects in Java.

As regards Visitors, I cannot understand what you're trying to do, so I
cannot comment.

Regards

Ed Willink

On 27/07/2013 00:14, Jérôme Brügger wrote:
> Hello,
>
> Excuse me for the late response and the unclarity of my message. It
> think it will be better if I insert the part of the code that I use
> and explain my problem :
>
> EPackage.Registry registry = new EPackageRegistryImpl();
> registry.put(Projet01Package.eNS_URI, Projet01Package.eINSTANCE);
>
> EcoreEnvironmentFactory environmentFactory = new
> EcoreEnvironmentFactory(registry);
> OCL ocl = OCL.newInstance(environmentFactory);
>
> File file = new
> File("C:/Users/jerome/workspace/OCLToPLSQL/model/projet01.ocl");
> InputStream in = new FileInputStream(file);
>
> Map<String, Constraint> constraintMap = new HashMap<String,
> Constraint>();
>
> try {
>
> OCLInput document = new OCLInput(in);
>
> List<Constraint> constraints = ocl.parse(document);
>
> Integer numberConstraint = 0;
>
> for (Constraint next : constraints) {
>
> if(next.getStereotype().toString() == "invariant")
> {
>
> String actualContext =
> contexteWithoutSelf(next.getSpecification().getContextVariable().toString());
>
> constraintMap.put(next.getName(), next);
>
> Iterator<EObject> body =
> next.getSpecification().eAllContents();
>
> Map mapSpecsFromTreeIte = new HashMap();
>
> Integer numberMapSpecsFromTreeIterator = 0;
>
> String globalconstraint =
> next.getSpecification().getBodyExpression().toString();
>
> Boolean isSimpleCycleConstraint =
> globalconstraint.matches("^self\\.([a-z]+\\.){2}=\\(self\\.[a-z]+\\.[a-z]+\\)$");
>
> Boolean isComplexConstraint =
> globalconstraint.matches("^(([a-z]+\\.){3}=\\([a-z]+\\.[a-z]+\\))|(([a-z]+\\.){2}=\\(([a-z]+\\.){2}[a-z]+\\))|(([a-z]+\\.){3,}=\\(([a-z]+\\.){2,}[a-z]+\\))$");
>
> if(isSimpleCycleConstraint == true) {
>
> String specsFromTreeIteValueTemp = null;
>
> Integer numberParsedConstraint = 0;
>
> while(body.hasNext()) {
>
> String containBodyConstraint =
> body.next().toString();
>
> Boolean regExForValideConstraint =
> BodyConstraintSelfOnly(containBodyConstraint);
>
> if (regExForValideConstraint == true) {
>
> if (numberMapSpecsFromTreeIterator % 2 == 0) {
>
> specsFromTreeIteValueTemp =
> containBodyConstraint;
>
> }
> else {
>
> String[] entityWithoutObject =
> containBodyConstraint.split("\\(expression: ");
>
> String mapSpecsFromTreeIteKey =
> entityWithoutObject[1].substring(0, entityWithoutObject[1].length()-1);
>
> if
> (!mapSpecsFromTreeIteKey.equals("Boolean")) {
>
> if
> (!mapSpecsFromTreeIteKey.equals(actualContext)) {
>
> mapSpecsFromTreeIte.put(numberParsedConstraint, new
> ParsedConstraint(numberConstraint, actualContext,
> parsedConstraintWithoutSelf(specsFromTreeIteValueTemp),
> mapSpecsFromTreeIteKey));
> numberParsedConstraint++;
>
> }
> }
>
> }
>
> }
>
> numberMapSpecsFromTreeIterator++;
>
> }
>
> (This is a prototype). So first, I load the metamodel and load OCL
> constraints from a file. After I just do some checks to restrict the
> transformation to some specifics pattern (cycle constraints). Just
> after, I do something that I think that is not so good and I need help
> for this case : I iterate through "Iterator<EObject> body" but use an
> even/odd condition and even with that I cannot retrieve the top of the
> AST (with other aberrations that I could not avoid). There's somthing
> like a vistor pattern but I havn't understand if that feet that case
> too. Per exemple, this code will give the return that I wrote before.
> I hope that someone could help us on this case.
>
> Best regards,
> J.Brügger
Re: Transform OCL into PL/SQL [message #1074843 is a reply to message #1067141] Sat, 27 July 2013 23:44 Go to previous messageGo to next message
Jérôme Brügger is currently offline Jérôme BrüggerFriend
Messages: 5
Registered: July 2013
Junior Member
Hi,

First thanks for your answer. The final goal is to transform OCL into PL-SQL trigger. For that, we are trying to understand how to retrive all informations of a constraint. This is the actual model that we are using for the first version :

[see_attachment_file]

And the OCL code that is passed to the main code :
import 'platform:/resource/OCLToPLSQL/model/projet01.ecore'

package projet01

context Realisation
inv : necessite.mene = realise.detient

endpackage


And the refine code :
package ch.hearc.ig.ocltoplsql.main;

public class Main {
	
	public static void main(String[] args) throws ParserException, IOException {
		
		EPackage.Registry registry = new EPackageRegistryImpl();
		registry.put(Projet01Package.eNS_URI, Projet01Package.eINSTANCE);
		EcoreEnvironmentFactory environmentFactory = new EcoreEnvironmentFactory(registry);
		OCL ocl = OCL.newInstance(environmentFactory);
		File file = new File("C:/Users/jerome/workspace/OCLToPLSQL/model/projet01.ocl");
		InputStream in = new FileInputStream(file);
		Map<String, Constraint> constraintMap = new HashMap<String, Constraint>();

		try {
			
		    OCLInput document = new OCLInput(in);
		    List<Constraint> constraints = ocl.parse(document);
		    Integer numberConstraint = 0;
		    
		    for (Constraint next : constraints) {
		    		
			        constraintMap.put(next.getName(), next);
			        Iterator<EObject> body = next.getSpecification().eAllContents();
		    			
				        while(body.hasNext()) {
				        	
				        	String containBodyConstraint = body.next().toString();
				        	System.out.println(containBodyConstraint);
				        	
				        }
		    	
		    	numberConstraint++;
		    	
		    }
		    
		}
		finally {
			
		    in.close();
		    
		}
		
	}
	
}


And this is the return of the execution of this code :
self.necessite.mene.=(self.realise.detient)
org.eclipse.emf.ecore.impl.EGenericTypeImpl@68de462 (expression: Boolean)
self.necessite.mene
org.eclipse.emf.ecore.impl.EGenericTypeImpl@4d8ce14a (expression: Departement)
self.necessite
org.eclipse.emf.ecore.impl.EGenericTypeImpl@5c1ae90c (expression: Projet)
self
org.eclipse.emf.ecore.impl.EGenericTypeImpl@6aba4211 (expression: Realisation)
self.realise.detient
org.eclipse.emf.ecore.impl.EGenericTypeImpl@6a47a0d4 (expression: Departement)
self.realise
org.eclipse.emf.ecore.impl.EGenericTypeImpl@48ff4cf (expression: Employe)
self
org.eclipse.emf.ecore.impl.EGenericTypeImpl@7114460 (expression: Realisation)
self : Realisation
org.eclipse.emf.ecore.impl.EGenericTypeImpl@7e9ffe3f (expression: Realisation)


The main problem I have is how to process the AST. Like you see, on this case, the "=" (must be the root) is not return.

If I try to use the eContrainer() before the while like that :
EObject test = next.eContainer();
System.out.println(test);


The return is simply "null". Have you got an idea to help us on this case ?

Best regards,
J.Brügger
  • Attachment: model.png
    (Size: 21.87KB, Downloaded 225 times)

[Updated on: Sat, 27 July 2013 23:46]

Report message to a moderator

Re: Transform OCL into PL/SQL [message #1075600 is a reply to message #1074843] Mon, 29 July 2013 18:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You don't give me enough to able to reproduce or understand your problem.

Zipping up an example project will generally me and ytou a lot of time.

You may find the new experimental pivot-based OCL easier to work with;
it is UML-aligned and templated types are visitable just like other AST
nodes.

If you're interested in code generation you may want to look at the OCL
to Java code generator which is designed to be extensible (codegen
plugin). However there are a variety of improvements still in progress
such as Common Subexpressiion Elimination and Function Inlining.

Regards

Ed Willink

On 28/07/2013 00:44, Jérôme Brügger wrote:
> Hi,
>
> First thanks for your answer. The final goal is to transform OCL into
> PL-SQL trigger. For that, we are trying to understand how to retrive
> all informations of a constraint. This is the actual model that we are
> using for the first version :
>
>
>
> And the OCL code that is passed to the main code :
> import 'platform:/resource/OCLToPLSQL/model/projet01.ecore'
>
> package projet01
>
> context Realisation
> inv : necessite.mene = realise.detient
>
> endpackage
>
> And the refine code :
> package ch.hearc.ig.ocltoplsql.main;
>
> public class Main {
>
> public static void main(String[] args) throws ParserException,
> IOException {
>
> EPackage.Registry registry = new EPackageRegistryImpl();
> registry.put(Projet01Package.eNS_URI, Projet01Package.eINSTANCE);
> EcoreEnvironmentFactory environmentFactory = new
> EcoreEnvironmentFactory(registry);
> OCL ocl = OCL.newInstance(environmentFactory);
> File file = new
> File("C:/Users/jerome/workspace/OCLToPLSQL/model/projet01.ocl");
> InputStream in = new FileInputStream(file);
> Map<String, Constraint> constraintMap = new HashMap<String,
> Constraint>();
>
> try {
>
> OCLInput document = new OCLInput(in);
> List<Constraint> constraints = ocl.parse(document);
> Integer numberConstraint = 0;
> for (Constraint next : constraints) {
>
> constraintMap.put(next.getName(), next);
> Iterator<EObject> body =
> next.getSpecification().eAllContents();
>
> while(body.hasNext()) {
>
> String containBodyConstraint =
> body.next().toString();
> System.out.println(containBodyConstraint);
>
> }
>
> numberConstraint++;
>
> }
> }
> finally {
>
> in.close();
> }
>
> }
>
> }
>
> And this is the return of the execution of this code :
> self.necessite.mene.=(self.realise.detient)
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@68de462 (expression: Boolean)
> self.necessite.mene
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@4d8ce14a (expression:
> Departement)
> self.necessite
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@5c1ae90c (expression: Projet)
> self
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@6aba4211 (expression:
> Realisation)
> self.realise.detient
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@6a47a0d4 (expression:
> Departement)
> self.realise
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@48ff4cf (expression: Employe)
> self
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@7114460 (expression:
> Realisation)
> self : Realisation
> org.eclipse.emf.ecore.impl.EGenericTypeImpl@7e9ffe3f (expression:
> Realisation)
>
>
> The main problem I have is how to process the AST. Like you see, on
> this case, the "=" (must be the root) is not return.
>
> If I try to use the eContrainer() before the while like that :
> EObject test = next.eContainer();
> System.out.println(test);
>
> The return is simply "null". Have you got an idea to help us on this
> case ?
>
> Regards,
> J.Brügger
Re: Transform OCL into PL/SQL [message #1075953 is a reply to message #1075600] Tue, 30 July 2013 11:50 Go to previous message
Jérôme Brügger is currently offline Jérôme BrüggerFriend
Messages: 5
Registered: July 2013
Junior Member
Hi again,

First thanks for the time that you take for help me.

Here's the link to the working projet exactly like in the previous post : http://www.djavalon.ch/OCLToPLSQLECLFOR.zip
(The link to the OCL's file must be changed)

The problem is that the new pivot-based Eclipse OCL in an experimental state and this projet need stable librairies. Perhaps make a gencode will be an answer but I think this will be one of the final step.

So the thing that is important is how to find the root of the tree that containt the only OCL constraint (in that case). I hope the project will help you to understand my problem.

Best regards,
J.Brügger

(Edit for the link.)

[Updated on: Sat, 17 August 2013 21:35]

Report message to a moderator

Previous Topic:illegal operation signature: (oclContents())
Next Topic:OCLStdLib extension
Goto Forum:
  


Current Time: Thu Mar 28 18:56:22 GMT 2024

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

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

Back to the top