| [news.eclipse.modeling.m2m] Re: QVT XSD |
Hello,
Ed, thank you for pointing about XSD serialization issues.
modeltype ecore uses ecore('http://www.eclipse.org/emf/2002/Ecore');
modeltype XSD uses "http://www.eclipse.org/xsd/2002/XSD";transformation interop2xsd(in interop: ecore , out XSD);
import library org.eclipse.m2m.qvt.oml.ocl.emf.libraries.XSDUtil;
main(in interopModel: EClass, out xsd: XSD::XSDSchema) {
xsd:= interopModel.map interop2Xsd();
}
Regards, Sergey.
Sergey,
Just note that XSD wasn't designed to serialize as XMI:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166638
It's there some way to accomplish what's done like this with the Java APIs can be expressed in QVT?
http://download.eclipse.org/modeling/emf/emf/javadoc/xsd/2.4.0/org/eclipse/xsd/util/XSDPrototypicalSchema.html#initializePrototypeSchema() <http://download.eclipse.org/modeling/emf/emf/javadoc/xsd/2.4.0/org/eclipse/xsd/util/XSDPrototypicalSchema.html#initializePrototypeSchema%28%29>
Sergey Boyko wrote:Hi Min,
I'm not quite familiar with XSDResourceImpl but seems that your case somehow depends on ones behavior. Namely on XSDResourceImpl.serialize(..) impl.
For your case just try to specify output URI with file extension differ from ".xsd" (for example ".xsde"). That way I've got the following output:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:XSDSchema xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsd="http://www.eclipse.org/xsd/2002/XSD" argetNamespace="DUMMY"/>
Regards, Sergey.
Min wrote:Hi,
1. QVT -
Executing the following .qvto :
modeltype INTEROP uses "http://ms.com/interop"; modeltype XSD uses "http://www.eclipse.org/xsd/2002/XSD";
transformation interop2xsd(in interop: INTEROP , out XSD);
main(in interopModel: INTEROP::InteropSchema, out xsd: XSD::XSDSchema) {
xsd:= interopModel.map interop2Xsd();
}
mapping INTEROP::InteropSchema::interop2Xsd() : XSD::XSDSchema { targetNamespace := 'DUMMY'; }
with OUT target file specifies as <something>.xsd, produces:
<?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="DUMMY"/>
which does not look like a valid xsd schema root element.
2. Java- On the other hand, running the following Java code:
class Schema {
private XSDFactory _xsdFactory;
private XSDSchema _schema;
private ByteArrayOutputStream _outputStream = new ByteArrayOutputStream();
private Schema() {
_xsdFactory = XSDFactory.eINSTANCE;
initSchema(); }
private void initSchema() {
_schema = _xsdFactory.createXSDSchema();
_schema.setTargetNamespace("DUMMY");
_schema.setSchemaForSchemaQNamePrefix("xsd");
Map<String, String> qNamePrefixToNamespaceMap =_schema.getQNamePrefixToNamespaceMap();
qNamePrefixToNamespaceMap.put("tns", _schema.getTargetNamespace());
qNamePrefixToNamespaceMap.put(_schema.getSchemaForSchemaQNamePrefix(), XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
_schema.updateElement();
}
private String serialize() {
XSDResourceImpl.serialize(_outputStream, _schema.getDocument());
return _outputStream.toString();
}
public static void main(String [ ] args) {
Schema schema = new Schema();
System.out.println(schema.serialize());
}
}
produces, in stdout:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:tns="DUMMY" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="DUMMY"/>
which looks like a valid xsd schema document root.
3. Question: how would one achieve the equivalence of 2. above,
with a QVT transform? I.e., how would one re-write the .qvto in 1. to get the output produced in 2. ?
Thanks.
-Min
Attachment:
org.eclipse.m2m.qvt.oml.ocl.emf.libraries_1.0.0.200806091156.jar
Description: Binary data