Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Problem trying to assign types to elements in the target model
Problem trying to assign types to elements in the target model [message #1764458] Tue, 30 May 2017 07:25 Go to next message
Bea Perez is currently offline Bea PerezFriend
Messages: 20
Registered: July 2012
Junior Member
Hello,

I am trying to perform a transformation from a model conforming with the UML metamodel to another model conforming with another metamodel called PROV. This PROV metamodel is a ecore metamodel generated from a XML Schema by means of the EMF plugin. Such a metamodel is well parsed. The point is that the generated PROV metamodel has some elements which reference to types of EMF and XML, and I do not know how to create such types in the target model. More specifically, I need to create target elements EReferences and EAttributes which have an attribute EType:
- of type "EFeatureMap [org.eclipse.emf.ecore.util.FeatureMap]", in the case of EReferences.
- of type "QName [javax.xml.namespace.QName] ", in the case of EAttributes.

I do not know how to create such ETypes for each case. ┬┐any idea? all help is wellcome.

Thanks
Bea

[Updated on: Tue, 30 May 2017 07:27]

Report message to a moderator

Re: Problem trying to assign types to elements in the target model [message #1767637 is a reply to message #1764458] Fri, 07 July 2017 20:22 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 357
Registered: September 2012
Location: Belgium
Senior Member

You cannot create those types directly in ATL. I'm also not sure you need to set those properties directly, because they may be derived from other properties in the same EClass. Example:

The following XSD element type specifies that a number of child elements can occur in any order, but the order is always preserved:
      <xsd:element name="regimen" minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>ordered day regimen of administration applicable either on a precised day or on basis of the frequency </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
          <xsd:sequence maxOccurs="unbounded">
            <xsd:choice minOccurs="0">
              <xsd:element name="daynumber" type="xsd:positiveInteger">
                <xsd:annotation>
                  <xsd:documentation>to be used to precise the day of the week of applicability in case of dosage regimen changing over time</xsd:documentation>
                </xsd:annotation>
              </xsd:element>
              <xsd:element name="date" type="DT:date">
                <xsd:annotation>
                  <xsd:documentation>to be used to precise the date of applicability</xsd:documentation>
                </xsd:annotation>
              </xsd:element>

              <xsd:element name="weekday">
                <xsd:annotation>
                  <xsd:documentation>to be used to precise the day of the week of applicability</xsd:documentation>
                </xsd:annotation>
                <xsd:complexType>
                  <xsd:complexContent>
                    <xsd:extension base="weekdayType">
                      <xsd:sequence>
                        <xsd:element name="weeknumber" type="xsd:positiveInteger" minOccurs="0" />
                      </xsd:sequence>
                    </xsd:extension>
                  </xsd:complexContent>

                </xsd:complexType>
              </xsd:element>
            </xsd:choice>
            <xsd:element name="daytime" minOccurs="0">
              <xsd:annotation>
                <xsd:documentation>proposed time of administration</xsd:documentation>
              </xsd:annotation>
              <xsd:complexType>
                <xsd:choice>
                  <xsd:element name="time" type="DT:time">
                    <xsd:annotation>
                      <xsd:documentation>proposed hour-min of administration</xsd:documentation>
                    </xsd:annotation>
                  </xsd:element>
                  <xsd:element name="dayperiod" type="dayperiodType">
                    <xsd:annotation>
                      <xsd:documentation>e.g. before noon</xsd:documentation>
                    </xsd:annotation>
                  </xsd:element>
                </xsd:choice>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="quantity" type="administrationquantityType">
              <xsd:annotation>
                <xsd:documentation>number of pharmaceutical product units per intake / per administration (piece, puff, ml,...)</xsd:documentation>
              </xsd:annotation>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>


This is translated to Ecore as follows:
index.php/fa/29893/0/

The "group" EAttribute has this strange List of EFeatureMapEntry type, which cannot be used directly in ATL. It only serves to return the XML child elements in their original order, however, which is something that Ecore does not support (child elements are always grouped per property, never stored "loose" under the parent).

In order to create an XML document that leverages this specific XML-only ordering, ATL must add the child elements in the order they should be written, which requires imperative code:

lazy rule CodedPosologyDayNumberRegimen {
	from
		s : EMRS!CodedPosology (
			s.isDayNumberPosologyWithMoments
		)
	to
		t : KMEHR!RegimenType
	do {
		-- [DMW] Daytimes and quantities must be added in a pairwise way:
		for (e in s.entries) {
			for (m in e.momentsOfIntakeWithDosage) {
				t.refGetValue('daynumber').add(e.dayNumber.toBigInteger());
				t.refGetValue('daytime').add(thisModule.MomentOfIntakeToDaytime(m));
				t.refGetValue('quantity').add(thisModule.MomentOfIntakeToAdministrationquantity(m));
			}
		}
		t;
	}
}


There are frequently other XML-specific datatypes inserted in your Ecore meta model, such as BigInteger and XMLGregorianCalendar. You'll probably need EMFTVM and its ability to access any Java method to work with these datatypes, for example:

--- Returns the current date/time.
helper def : currentDateTime : "#native"!"java::util::Date" =
	"#native"!"java::util::Date".newInstance();

--- Returns the current date (yyyy-MM-dd).
helper def : currentDate : "#native"!"javax::xml::datatype::XMLGregorianCalendar" =
	let date : String = thisModule.currentDateTime.toString('yyyy-MM-dd') in
    "#native"!"javax::xml::datatype::DatatypeFactory".refInvokeStaticOperation('newInstance', Sequence{}).newXMLGregorianCalendar(date);	


Cheers,
Dennis
Previous Topic:Tutorials for working with UML Stereotypes and Composite Structure Diagrams
Next Topic:Obtaining ATL program from ATL model
Goto Forum:
  


Current Time: Fri Apr 20 11:05:36 GMT 2018

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

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