Java Reference
In-Depth Information
13.5.4 Object Creation and Population
As mentioned earlier, a mapping invocation implicitly creates an instance of the
declared return type or types. The features of instantiated elements are set using
the assignment operator ( := ), as shown earlier with the name := self.name
statement. Although this works for mappings of simple attributes of the same
type, more complex mappings necessarily require more complex expressions.
Note that a second assignment operator ( += ) is available for adding to collec-
tions.
To create an object within the context of an operation, use the object key-
word. Following is a basic object expression that creates an instance of
PrimitiveDataType and assigns it to the type reference in the TableColumn
object created by the mapping:
type := object RDB::datatypes::PrimitiveDataType {
name := 'int';
};
In fact, the entire body of a mapping can be contained within an object
block, as shown in the complete mapping definition. This is not necessary, how-
ever, because the return type of the mapping is enough to determine what the
body is instantiating.
mapping UML::Property::primitiveAttribute2column( in targetType:
UML::DataType) : RDB::TableColumn
when { self .isPrimitive() }
{
object RDB::TableColumn {
isPrimaryKey := self .isPrimaryKey();
name := self .name;
type := object RDB::datatypes::PrimitiveDataType {
name := umlPrimitive2rdbPrimitive( self .type.name);
};
}
}
A common use of object is to initialize variables in the init section. For exam-
ple, the following snippet has a variable primitiveType assigned to an object
that was created and initialized using the umlPrimitive2rdbPrimitive()
query, which is later used to set the TableColumn 's type reference.
Search WWH ::




Custom Search