Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » serialization of CompleteOCL document to XMI format
serialization of CompleteOCL document to XMI format [message #986595] Wed, 21 November 2012 06:55 Go to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi all,
I would like to know if it is possible to serialize an CompleteOCL document to xmi format? If yes, how exactly please?

I have an completeOCL document like this

import 'MyEcore.ecore'
package test

context TestClass
...
....

I would like to generate the xmi file which refers to the ecore elements (classes, packages, attributes, etc.)

Please help me
Best regards

[Updated on: Wed, 21 November 2012 06:56]

Report message to a moderator

Re: serialization of CompleteOCL document to XMI format [message #986630 is a reply to message #986595] Wed, 21 November 2012 09:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

The CST can be serialized by saving the CST Resource to an XMI file.

(This is currently only available programmatically.)

The AST can be serialized by saving the AST (Pivot) Resource to an XMI
file, but since Complete OCL complements an existing meta-model, this
also serialises the complemented meta-model.

(This might be available interactively by using Load Complete OCL
Resource to merge into the Sampkle Excore Editior, then doing SaveAs...)

Regards

Ed Willink

On 21/11/2012 06:55, Fy Za wrote:
> Hi all, I would like to know if it is possible to serialize an
> CompleteOCL document to xmi format? If yes, how exactly please?
>
> I have an completeOCL document like this
>
> import 'MyEcore.ecore'
> package test
>
> context TestClass
> ...
> ....
>
> I would like to generate the xmi file which refers to the ecore
> elements (classes, packages, attributes, etc.)
>
> Please help me
> Best regards
>
>
Re: serialization of CompleteOCL document to XMI format [message #989914 is a reply to message #986630] Mon, 10 December 2012 01:31 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi Ed,
How to serialize the AST of a CompleteOCL Document programmatically?
There is some code in tests packages?
Can you please help me!

Best regards,
Fy Za
Re: serialization of CompleteOCL document to XMI format [message #989930 is a reply to message #989914] Mon, 10 December 2012 06:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

I didn't understand your last question so I gave you two answers.

You haven't indicated which you have tried or what you wanted.

Basically you just use the standard EMF Resource.save() and when looking
for examples you can always use Eclipse search tools such as File or
Java search.

Regards

Ed Willink


On 10/12/2012 01:31, Fy Za wrote:
> Hi Ed,
> How to serialize the AST of a CompleteOCL Document programmatically?
> There is some code in tests packages?
> Can you please help me!
>
> Best regards,
> Fy Za
Re: serialization of CompleteOCL document to XMI format [message #990000 is a reply to message #989930] Mon, 10 December 2012 12:18 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi Ed,
I am sorry whether it is not very clear.
I try to serialize a CompleteOCLDocument in order to generate the AST
programmatically.

I dont find codes in sources of OCL (in the Git).

Best regards
Fy Za
Re: serialization of CompleteOCL document to XMI format [message #990033 is a reply to message #990000] Mon, 10 December 2012 15:45 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
To be more precise,
I have an OCLDocument test.ocl with applied to Simple.ecore

I define this class:
package Parser;

import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;


public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		resource.load(null);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".generated.xmi"));
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);

	}
}

It generates a file which named test.generated.xmi

I generate another xmi file with saveAs xmi command of test.ocl named test.saveas.xmi

test.generated.xmi doesn't resolve paths (like in this example test.ocl#xtextLink_::0.10.0.6.1.0::2::/1)
  <ownedImport>
    <pathName>
      <path xsi:type="baseCST:PathElementWithURICS">
        <element xsi:type="pivot:Annotation" href="/CompleteOCLParser/Case/test.ocl#xtextLink_::0.10.0.6.1.0::2::/1"/>
      </path>
    </pathName>
  </ownedImport>

However the test.saveas.xmi resolve them (Simple.ecore#/)
  <ownedImport>
    <namespace xsi:type="pivot:Model" href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
  </ownedImport>


So, What I should modify or add in the parser class to get the results of test.saveas.xmi programmaticly ?

Best regards,
Fy Za

[Updated on: Mon, 10 December 2012 15:46]

Report message to a moderator

Re: serialization of CompleteOCL document to XMI format [message #990056 is a reply to message #990033] Mon, 10 December 2012 16:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

Use EcoreUtil.resolveAll.

You haven't motivated your use of a saved Complete OCL and I cannot
envisage why it would be helpful, so I suspect you have many more
problems in stire.

Regards

Ed Willink

On 10/12/2012 15:45, Fy Za wrote:
> To be more precise,
> I have an OCLDocument test.ocl with applied to Simple.ecore
>
> I define this class:
>
> package Parser;
>
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
>
>
> public class Parser {
>
> public static void main(String[] args) throws IOException {
>
> CompleteOCLStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI(args[0]));
> resource.load(null);
> Resource resourceAsXmi =
> resourceSet.createResource(URI.createURI(args[0]+".generated.xmi"));
> resourceAsXmi.getContents().addAll(resource.getContents());
> resourceAsXmi.save(null);
>
> }
> }
>
> It generates a file which named test.generated.xmi
>
> I generate another xmi file with saveAs xmi command of test.ocl named
> test.saveas.xmi
>
> The difference test.generated.xmi doesn't resolve paths (like in this
> example test.ocl#xtextLink_::0.10.0.6.1.0::2::/1)
>
> <ownedImport>
> <pathName>
> <path xsi:type="baseCST:PathElementWithURICS">
> <element xsi:type="pivot:Annotation"
> href="/CompleteOCLParser/Case/test.ocl#xtextLink_::0.10.0.6.1.0::2::/1"/>
> </path>
> </pathName>
> </ownedImport>
>
> However the test.saveas.xmi resolve them (Simple.ecore#/)
>
> <ownedImport>
> <namespace xsi:type="pivot:Model"
> href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
> </ownedImport>
>
>
> So, What I should modify or add in the parser class to get the results
> of test.saveas.xmi programmaticly ?
>
> Best regards,
> Fy Za
Re: serialization of CompleteOCL document to XMI format [message #990069 is a reply to message #990056] Mon, 10 December 2012 17:45 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
when I use EcoreUtil.resolveAll(resource);
package Parser;





import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;









public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		resource.load(null);
		EcoreUtil.resolveAll(resource);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);

	}
}


I have errors:
Exception in thread "main" org.eclipse.ocl.examples.pivot.utilities.IllegalLibraryException: No OCL Standard Library content available
	at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.getRequiredLibraryType(PivotStandardLibrary.java:278)
	at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.resolveRequiredSimpleType(PivotStandardLibrary.java:377)
	at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.getOclInvalidType(PivotStandardLibrary.java:207)
	at org.eclipse.ocl.examples.xtext.base.baseCST.impl.PathElementCSImpl.getElement(PathElementCSImpl.java:354)
	at org.eclipse.ocl.examples.xtext.base.baseCST.impl.PathNameCSImpl.getElement(PathNameCSImpl.java:391)
	at org.eclipse.ocl.examples.xtext.completeocl.completeOCLCST.impl.ClassifierContextDeclCSImpl.getClassifier(ClassifierContextDeclCSImpl.java:201)
	at org.eclipse.ocl.examples.xtext.completeocl.completeOCLCST.impl.ClassifierContextDeclCSImpl.eIsSet(ClassifierContextDeclCSImpl.java:168)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1237)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:401)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.next(EContentsEList.java:559)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences(EcoreUtil.java:302)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:296)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:281)
	at Parser.Parser.main(Parser.java:32)

Re: serialization of CompleteOCL document to XMI format [message #990079 is a reply to message #990069] Mon, 10 December 2012 18:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

If you Google for "No OCL Standard Library content available " you find
that the top hit is http://www.eclipse.org/forums/index.php/m/931858/

Regards

Ed Willink

On 10/12/2012 17:45, Fy Za wrote:
> No OCL Standard Library content available
Re: serialization of CompleteOCL document to XMI format [message #990128 is a reply to message #990079] Tue, 11 December 2012 00:56 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi Ed,
Thank you!
It is resolved!!
I add two lines
package Parser;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;

public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		OCLinEcoreStandaloneSetup.doSetup();
		OCLstdlib.install();
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		resource.load(null);
		EcoreUtil.resolveAll(resource);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);

	}
}

However, two differences between test.saveas.xmi and test.generated.xmi still persists:
1-
In the "save as xmi" file named test.saveas.xmi, I have a the top
<?xml version="1.0" encoding="ASCII"?>
<completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST" xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST" xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST" xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
  <ownedImport>
    <namespace xsi:type="pivot:Model" href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
  </ownedImport>

However, The parser generated file named test.generated.xmi, I have for the same part
<?xml version="1.0" encoding="ASCII"?>
<completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST" xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST" xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST" xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
  <ownedImport>
    <pathName>
      <path xsi:type="baseCST:PathElementWithURICS">
        <element xsi:type="pivot:Root" href="pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/Simple.ecore#/"/>
      </path>
    </pathName>
  </ownedImport>


2-
In the "save as xmi" file named test.saveas.xmi, I have for example (/null/Users/fyza/Modeling/workspace_ocl/)
<name xsi:type="essentialOCLCST:NameExpCS">
                  <pathName>
                    <path>
                      <element xsi:type="pivot:Variable" href="pivot:/null/Users/fyza/Modeling/workspace_ocl/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.0/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
                    </path>
                  </pathName>
                </name>

However, The parser generated file named test.generated.xmi, I have for the same part(/platform/resource/):
<name xsi:type="essentialOCLCST:NameExpCS">
                  <pathName>
                    <path>
                      <element xsi:type="pivot:Variable" href="pivot:/platform/resource/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.1/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
                    </path>
                  </pathName>
                </name>


Do you know what I should modify or add in the parser in order to eliminate these differences.

Best regards,
Fy Za

[Updated on: Tue, 11 December 2012 07:38]

Report message to a moderator

Re: serialization of CompleteOCL document to XMI format [message #990194 is a reply to message #990128] Tue, 11 December 2012 11:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore
indicates a file that was opened as
platform:/resource/CompleteOCLParser/Case/Simple.ecore

pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore
indicates a file that was opened as
file:/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore

if you want EMF to work consistently, you should avoid file: paths
wherever possible. Use URI.createPlatformResourceURI and
StandaloneProjectMap.

Regards

Ed Willink


On 11/12/2012 00:57, Fy Za wrote:
> Hi Ed,
> Thank you!
> I add two lines
>
> package Parser;
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
> import
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
> import
> org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
>
> public class Parser {
>
> public static void main(String[] args) throws IOException {
>
> CompleteOCLStandaloneSetup.doSetup();
> OCLinEcoreStandaloneSetup.doSetup();
> OCLstdlib.install();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI(args[0]));
> resource.load(null);
> EcoreUtil.resolveAll(resource);
> Resource resourceAsXmi =
> resourceSet.createResource(URI.createURI(args[0]+".xmi"));
> resourceAsXmi.getContents().addAll(resource.getContents());
> resourceAsXmi.save(null);
>
> }
> }
>
> However, two differences still persists:
> 1-
> In the "save as xmi" file named test.saveas.xmi, I have a the top
> <?xml version="1.0" encoding="ASCII"?>
> <completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST"
> xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST"
> xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST"
> xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
> <ownedImport>
> <namespace xsi:type="pivot:Model"
> href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
> </ownedImport>
> However, The parser generated file named test.generated.xmi, I have
>
> <?xml version="1.0" encoding="ASCII"?>
> <completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST"
> xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST"
> xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST"
> xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
> <ownedImport>
> <pathName>
> <path xsi:type="baseCST:PathElementWithURICS">
> <element xsi:type="pivot:Root"
> href="pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore#/"/>
> </path>
> </pathName>
> </ownedImport>
>
>
> 2- In the "save as xmi" file named test.saveas.xmi, I have for example
>
> <name xsi:type="essentialOCLCST:NameExpCS">
> <pathName>
> <path>
> <element xsi:type="pivot:Variable"
> href="pivot:/null/Users/fyza/Modeling/workspace_ocl/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.0/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
> </path>
> </pathName>
> </name>
>
> However, The parser generated file named test.generated.xmi, I have
>
> <name xsi:type="essentialOCLCST:NameExpCS">
> <pathName>
> <path>
> <element xsi:type="pivot:Variable"
> href="pivot:/platform/resource/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.1/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
> </path>
> </pathName>
> </name>
>
>
> Do you know what I should modify or add in the parser in order to
> eliminate these differences.
> Best regards,
> Fy Za
Re: serialization of CompleteOCL document to XMI format [message #990235 is a reply to message #990194] Tue, 11 December 2012 14:22 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi,
I add this line:
URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);

However, for StandaloneProjectMap, I don't know what I should define, what method, what parameters!!!! etc.
can you explain to me more, Please!
because I don't find nothing in Google Sad
package Parser;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;

public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		
		OCLinEcoreStandaloneSetup.doSetup();
		OCLstdlib.install();
		
		URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);
		System.out.println(uri);
		
		
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		resource.load(null);
		EcoreUtil.resolveAll(resource);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);

	}
}


Re: serialization of CompleteOCL document to XMI format [message #990273 is a reply to message #990235] Tue, 11 December 2012 16:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

Users of Eclipse are expected to be able to show some initiative....

Have you looked at the javadoc?

Have you searched for references?

Regards

ed Willink


On 11/12/2012 14:22, Fy Za wrote:
> Hi, I add this line: URI uri =
> URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);
>
> However, for StandaloneProjectMap, I don't know what I should define,
> what method, what parameters!!!! etc.
> can you explain to me more, Please!
> because I don't find nothing in Google :(
>
> package Parser;
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
> import
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
> import
> org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
>
> public class Parser {
>
> public static void main(String[] args) throws IOException {
>
> CompleteOCLStandaloneSetup.doSetup();
>
> OCLinEcoreStandaloneSetup.doSetup();
> OCLstdlib.install();
>
> URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore",
> true);
> System.out.println(uri);
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI(args[0]));
> resource.load(null);
> EcoreUtil.resolveAll(resource);
> Resource resourceAsXmi =
> resourceSet.createResource(URI.createURI(args[0]+".xmi"));
> resourceAsXmi.getContents().addAll(resource.getContents());
> resourceAsXmi.save(null);
>
> }
> }
>
>
>
Re: serialization of CompleteOCL document to XMI format [message #990357 is a reply to message #990273] Wed, 12 December 2012 07:08 Go to previous messageGo to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi Ed,
Yes, I look in javadoc.
There is no concrete code. There is just some discussions!
I edit the code, but no modifications in the generated xmi file.
Can you PLEASE edit this code!
at least, tell me, what I should do exactly with StandaloneProjectMap
and How relate it with the initial code?
regards!
Fy
package Parser;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;


import org.eclipse.ocl.examples.domain.utilities.ProjectMap;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IPackageDescriptor;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IProjectDescriptor;

import simplepdl.SimplepdlPackage;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.ProjectDescriptor;
public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		
		OCLinEcoreStandaloneSetup.doSetup();
		OCLstdlib.install();
		
		URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);
		System.out.println(uri);
		
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		
		String project = SimplepdlPackage.class.getPackage().getName();
		String modelPath = project + "/model/SimplePDL.ecore";
		ProjectMap.getResourceFactoryRegistry(null).getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
		URI nsURI = URI.createURI(SimplepdlPackage.eINSTANCE.getNsURI());
		URI pluginURI = URI.createPlatformPluginURI(modelPath, true);
		URI resourceURI = URI.createPlatformResourceURI(modelPath, true);
		
		ProjectMap projectMap = new ProjectMap();
		projectMap.initializeResourceSet(resourceSet);
		IProjectDescriptor projectDescriptor = projectMap.getProjectDescriptor(project);
		IPackageDescriptor packageDescriptor = projectDescriptor.getPackageDescriptor(URI.createURI(SimplepdlPackage.eINSTANCE.getNsURI()));
		packageDescriptor.setUseModel(true, resourceSet.getPackageRegistry());
		Resource registeredResource = resourceSet.getResource(nsURI, true);
		
		resource.load(null);
		EcoreUtil.resolveAll(resource);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);

	}
}

[Updated on: Wed, 12 December 2012 07:20]

Report message to a moderator

Re: serialization of CompleteOCL document to XMI format [message #990376 is a reply to message #990357] Wed, 12 December 2012 08:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

> Yes, I look in javadoc. There is no concrete code. There is just some
> discussions!
> I edit the code, but no modifications in the generated xmi file.
> Can you PLEASE edit this code!
No.

I'm sorry but if you are unable to read the Javadoc, look at the code or
search for examples, you should reconsider how you spend you time.

Regards

Ed Willink
Re: serialization of CompleteOCL document to XMI format [message #990448 is a reply to message #990376] Wed, 12 December 2012 14:33 Go to previous message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Hi Ed,
I read documentation,
I found the ProjectMapTest in org.eclipse.ocl.examples.test.ecore
I found also testProjectMap_Pivot_Local() method which can help me to resolve this problem.
I tryed to adopt it in my context, however, the problem still persists.
Best regards,

package Parser;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;


import org.eclipse.ocl.examples.domain.utilities.ProjectMap;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IPackageDescriptor;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IProjectDescriptor;

import simple.SimplePackage;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.ProjectDescriptor;
public class Parser {

	public static void main(String[] args) throws IOException {

		CompleteOCLStandaloneSetup.doSetup();
		OCLinEcoreStandaloneSetup.doSetup();
		OCLstdlib.install();
		
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource resource = resourceSet.createResource(URI.createURI(args[0]));
		resource.load(null);
		Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));


		
		String project = SimplePackage.class.getPackage().getName();
		System.out.println(project);
		
		ProjectMap.getResourceFactoryRegistry(null).getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
		
		ProjectMap projectMap = new ProjectMap();
		projectMap.initializeResourceSet(resourceSet);
		IProjectDescriptor projectDescriptor = projectMap.getProjectDescriptor(project);
		IPackageDescriptor packageDescriptor = projectDescriptor.getPackageDescriptor(URI.createURI(SimplePackage.eINSTANCE.getNsURI()));
		packageDescriptor.setUseModel(true, resourceSet.getPackageRegistry());
		

		
		
		EcoreUtil.resolveAll(resource);
		resourceAsXmi.getContents().addAll(resource.getContents());
		resourceAsXmi.save(null);
		
	}
}
Previous Topic:OCL in Xtext editor: Quick fixes for constraints
Next Topic:Using static variables in OCL constraints
Goto Forum:
  


Current Time: Fri Oct 24 14:46:29 GMT 2014

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

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