EMF >> Extended Metadata
//*** Initialize a BasicExtendedMetaData with an empty map
final ExtendedMetaData ext = new BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
EPackage.Registry.INSTANCE, new HashMap());
//*** This says that the package will be identified by the null namespace
ext.setQualified(EPO2Package.eINSTANCE, false);
//*** This is to set different names to use when serializing
ext.setName(EPO2Package.Literals.PURCHASE_ORDER, "order");
ext.setName(EPO2Package.Literals.PURCHASE_ORDER__ITEMS, "item");
//*** This is to specify that the comment attribute should be represented as an XML element (not an attribute)
ext.setFeatureKind(EPO2Package.Literals.PURCHASE_ORDER__COMMENT,
ExtendedMetaData.ELEMENT_FEATURE);
//*** Save the resource with extended options (Do similarly for loading)
Map options = new HashMap();
options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
resource.save(options);
>> This option is used to tailor XML serialization. If your model was defined using XMLSchema, you must
use this option to save and load instances of it.
>> An ExtendedMetaData implementation is used to handle any extended metadata annotations defined on the
Ecore model. It can specify how features are to be represented in the serialization and with what name.
//*** This sets up the OPTION_EXTENDED_META_DATA load option for a resource set
//*** getEcore2Xml(ResourceSet) gives an ExtendedMetaData implementation
resourceSet_p.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, getEcore2Xml(resourceSet_p));
EClass purchaseOrderClass = ...;
EAttribute orders = ecoreFactory.createEAttribute();
supplierClass.getEStructuralFeatures().add(orders);
orders.setName("orders");
orders.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
orders.setEType(EcorePackage.Literals.EFEATURE_MAP_ENTRY);
//*** This adds an extended metadata annotation with a "kind" details entry to the "orders" feature
ExtendedMetaData.INSTANCE.setFeatureKind(orders, ExtendedMetaData.GROUP_FEATURE);
//*** EMF provides an interface, ExtendedMetaData, that assists in recording, accessing, and interpreting
// annotations in meta-model
public interface ExtendedMetaData
{
...
String getName(EClassifier eClassifier);
void setName(EClassifier eClassifier, String name);
...
ExtendedMetaData INSTANCE = new BasicExtendedMetaData();
}
>> Extended metadata EAnnotations are used in models that were created from XML Schema to capture
details about the schema that have no other direct representation in Ecore.
>> Such annotations are identified by a source of "http://org/eclipse/emf/ecore/util/ExtendedMetaData"
>> In EMF book: 15.3.5. Extended Metadata