static model from xml [message #1709967] |
Fri, 02 October 2015 09:52 |
|
Hello
I work on xtext based application. Right now we use dynamic implementaion of model. It means : we have xml file that describe object in model and xsd file that is used for verification xml file. Metamodel is loaded from xml file using code like this
metamodel = new XSDMetaModel();
xsdFileName = FileSystem.getTypesXsdPath();
metamodel.addSchemaFile(xsdFileName);
XMLReaderImpl reader = new XMLReaderImpl(new ResourceSetImpl(), etamodel);
xmlFileName = FileSystemRegistry.getAtomFileSystem().getTypesXmlPath();
reader.setUri(xmlFileName);
EObject e = reader.readXML();
return e;
then we create actual object of semantic model via
public static EObject createEObject(final String name, final EPackage metamodel) {
EClass meta = (EClass) metamodel.getEClassifier(name);
if (meta != null) {
return metamodel.getEFactoryInstance().create(meta);
} else {
throw new RuntimeException("Metamodelelement " + name + " cannot be created. Probably a misstyping?");
}
}
[/code]
So we use dynamic implmentaion. Are there way to generate Java class from XML descriptionin compile time and used static implementation?
<type name="XXXT" schema="SHEMA" table="TABLE">
<attribute name="N1" type="String" />
<attribute name="N2" type="Integer"/>
</type>
I would like to create ecore file from this descprition like
<eClassifiers xsi:type="ecore:EClass" name="C1" eSuperTypes="//GENERICTYPE">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="C1">
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="C2">
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
[Updated on: Fri, 02 October 2015 10:57] Report message to a moderator
|
|
|
|
Re: static model from xml [message #1710215 is a reply to message #1710091] |
Mon, 05 October 2015 11:57 |
|
Thanks for the link. I generated corresponded editor. To my regret is unclear how to imported the xml description to generated editor. I can do it programmatically using code
metamodel = new XSDMetaModel();
xsdFileName = FileSystem.getTypesXsdPath();
metamodel.addSchemaFile(xsdFileName);
XMLReaderImpl reader = new XMLReaderImpl(new ResourceSetImpl(), etamodel);
xmlFileName = FileSystemRegistry.getTypesXmlPath();
reader.setUri(xmlFileName);
EObject e = reader.readXML();
return e
Can I do it in compile time and then using generated class instead of dynamic implementation?
[Updated on: Mon, 05 October 2015 11:57] Report message to a moderator
|
|
|
Re: static model from xml [message #1710256 is a reply to message #1710215] |
Mon, 05 October 2015 14:40 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Alex,
As I mentioned, I don't recognize these APIs. If you've followed a
tutorial, you can invoke Generate Test Code and look at the
XyzExample.Java to see to load XML purely with EMF using the generated
model in a stand alone program...
On 05/10/2015 1:57 PM, Alex Gor wrote:
> Thanks for the link. I generated corresponded editor. To my regret is
> unclear how to imported the xml description to generated editor. I can
> do it programmatically using code
> metamodel = new XSDMetaModel();
> xsdFileName = FileSystem.getTypesXsdPath();
> metamodel.addSchemaFile(xsdFileName);
> XMLReaderImpl reader = new XMLReaderImpl(new ResourceSetImpl(),
> etamodel);
> xmlFileName = FileSystemRegistry.getAtomFileSystem().getTypesXmlPath();
> reader.setUri(xmlFileName);
> EObject e = reader.readXML();
> return e
>
>
> Can I do it in compile time and then using generated class instead of
> dynamic implementation?
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03127 seconds