XML Schema (XSD) generation [message #1061358] |
Fri, 31 May 2013 06:22  |
Eclipse User |
|
|
|
Hi,
I've spent a good amount of time looking for some answers but got lost in all those Eclipse modelling technologies.
My ultimate goal is to transform an UML class model into an XSD. Transformation rules are very specific to my environment. I am wondering what is the best approach? I think about two options.
1. UML Model -> Model conforming to XSD metamodel -> XSD (text)
2. UML Model -> "Generic" ecore model -> XSD (text)
In case of 1) - how to export model conforming to XSD metamodel to the actual XSD?
In case of 2) - is it possible to customize a way how ecore to XSD is mapped (for example I would like EClass attributes not to be XSD attrbutes but elements of a complex type).
Thanks,
Michal
|
|
|
Re: XML Schema (XSD) generation [message #1061556 is a reply to message #1061358] |
Sun, 02 June 2013 16:19  |
Eclipse User |
|
|
|
Op 31-05-13 21:31, Michal Kleczek schreef:
> Hi,
> I've spent a good amount of time looking for some answers but got lost in all
> those Eclipse modelling technologies.
> My ultimate goal is to transform an UML class model into an XSD.
> Transformation rules are very specific to my environment. I am wondering what
> is the best approach? I think about two options.
> 1. UML Model -> Model conforming to XSD metamodel -> XSD (text)
This will not work, because the XSD metamodel needs "hacks" for it to work:
http://www.eclipse.org/forums/index.php?t=msg&th=443250/
ATL needs to do what's listed here:
http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.5/org.eclipse/xsd/2.5.0/org/eclipse/xsd/ecore/EcoreSchemaBuilder.java#EcoreSchemaBuilder.buildSchema%28org.eclipse.emf.ecore.EPackage%29
The following code:
-- @atlcompiler emftvm
-- @nsURI ECORE=http://www.eclipse.org/emf/2002/Ecore
-- @nsURI XSD=http://www.eclipse.org/xsd/2002/XSD
module EcoreToXSD;
create OUT : XSD from IN : ECORE;
rule EPackageToSchema {
from s : ECORE!EPackage
to t : XSD!XSDSchema (
targetNamespace <- s.nsURI
-- contents <- s.eClassifiers->select(c | c.oclIsKindOf(ECORE!EClass))
)
do {
t.setSchemaForSchemaQNamePrefix('xsd');
t.getQNamePrefixToNamespaceMap().put('xsd', 'http://www.w3.org/2001/XMLSchema');
}
}
rule EClassToComplexTypeDef {
from s : ECORE!EClass
to t : XSD!XSDComplexTypeDefinition (
name <- s.name)
}
gives:
org.eclipse.m2m.atl.emftvm.util.VMException: java.lang.IllegalAccessException:
Class org.eclipse.m2m.atl.emftvm.util.EMFTVMUtil can not access a member of
class org.eclipse.xsd.impl.XSDSchemaImpl$1 with modifiers "public volatile"
at public java.lang.Object
org.eclipse.xsd.impl.XSDSchemaImpl$1.put(java.lang.Object,java.lang.Object)
Local variables: []
at rule
EPackageToSchema@postApply#8(platform:/resource//org.eclipse.m2m.atl.emftvm.tests/test-data/EcoreToXSD.atl#[16:3-16:82])
Local variables: [__trace__: TRACE!TraceLink = 48c8175f:TRACE!TraceLink, s:
ECORE!EPackage = My:ECORE!EPackage, t: XSD!XSDSchema = 5ca65965:XSD!XSDSchema]
at static EMFTVM!ExecEnv::main() :
Object(platform:/resource//org.eclipse.m2m.atl.emftvm.tests/test-data/EcoreToXSD.atl)
Local variables: []
Apparently, xpand has managed those hacks, though:
https://github.com/eclipse/xpand/blob/master/examples/org.eclipse.xpand.examples.xsd.m2m.ecore2xsd/src/xsd/m2m/ecore2xsd/ecore2xsd.ext
> 2. UML Model -> "Generic" ecore model -> XSD (text)
>
> In case of 1) - how to export model conforming to XSD metamodel to the actual
> XSD?
> In case of 2) - is it possible to customize a way how ecore to XSD is mapped
> (for example I would like EClass attributes not to be XSD attrbutes but
> elements of a complex type).
UML Model -> Ecore Model is possible in ATL.
Ecore Model -> XSD customisation can be done by creating a new "Ecore To XML
Mapping" file. I don't know the details.
>
> Thanks,
> Michal
>
Cheers,
Dennis
|
|
|
Powered by
FUDForum. Page generated in 0.05900 seconds