Top Banner
Java Metadata Interface - 1 - © 2006 LIP6 A presentation of JMI A presentation of JMI Java Metadata Interface Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine Scott 75015 Paris, France http://www-src.lip6.fr/homepages/Marie-Pierre.Gervais
33

Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Apr 01, 2015

Download

Documents

Kai Wommack
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 1 - © 2006 LIP6

A presentation of JMIA presentation of JMIJava Metadata InterfaceJava Metadata Interface

LIP6, Laboratoire d'Informatique de Paris 68, rue du Capitaine Scott

75015 Paris, Francehttp://www-src.lip6.fr/homepages/Marie-Pierre.Gervais

Page 2: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 2 - © 2006 LIP6

Context of this work

• The present courseware has been elaborated in the context of ModelWare European IST FP6 project (http://www.modelware-ist.org/)

• The MODELWARE project (Modelling solution for software systems) brings together 19 partners from Europe and Israel. Its main objectives are to develop a solution to reduce the cost of software systems large-scale deployment by the means of Model Driven Development techniques.

• To achieve the goals of large-scale dissemination of MDD techniques, ModelWare is also promoting the idea of collaborative development of courseware in this domain.

• The MDD courseware provided here with the status of open source software is produced under the EPL 1.0 licence.

Page 3: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 3 - © 2006 LIP6

Outline

• Overview of the standard

• The JMI interfaces categories

• The reflective interfaces• Translation rules

• An exemple : the Use Case Diagram

• The tailored interfaces• Translation rules

• An exemple : the Use Case Diagram

Page 4: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 4 - © 2006 LIP6

Rationale

• A model is an abstract entity • A model is structured by its metamodel• A metamodel is an abstract entity• A metamodel is structured by MOF• MOF is an abstract entity!

• To handle (meta*)models, they need to be represented in an electronic format

Page 5: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 5 - © 2006 LIP6

Java Model Interface

• Defined by JCP (Java Community Process)

• Enable to represent models in the form of Java objects

• Defines rules enabling to build Java interfaces from a metamodel• JMI1.0 (final release, 28 June 2002) applies to MOF1.4

Page 6: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 6 - © 2006 LIP6

JMI: principle

metamodel

models

Java Interface

Java Objects

Page 7: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 7 - © 2006 LIP6

JMI

• Java API for handling models• Interfaces providing operations

• Develop a CASE tool for handling a model = develop a program using (invoking) the API

Page 8: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 8 - © 2006 LIP6

The JMI Interfaces

• Two categories• Reflective

•Provides means to dynamically discover information on a model element (i.e., access to its meta-class)

•Usable for all types of models• Independent from the metamodel

• A model is a set of linked model elements, instances of meta-classes

• Tailored•Dedicated to a type of models (models that are instances of

the same metamodel)•Depending on the structure of this type of models (i.e.,

depending on the metamodel)

Page 9: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 9 - © 2006 LIP6

The Reflective Interfaces

Page 10: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 10 - © 2006 LIP6

RefBaseObject

• Represents any element (of a model or of a metamodel)

• Offers the refMetaObject() operation• Returns the metaclass of the element

• Type of the metaclass : refObject (inherits from RefBaseObject)

• Enables the navigation to the meta levels for discovering the structure of models.

Page 11: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 11 - © 2006 LIP6

RefFeatured

• Specialization of RefBaseObject• Offers operations to access the element properties

• Attribute, reference, operation

• refGetValue() and refSetValue() operations • Read and Write the property value• Signatures:

• void refSetValue(String propName, Object propValue)

• Object refGetValue(String propName)

• Input parameter propName: a string identifying the property

Page 12: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 12 - © 2006 LIP6

RefClass

• Specialization of RefFeatured

• Represents the notion of element factory• Enables to build instances of a metaclass

• There is a RefClass per a metaclass

• Offers the refCreateInstance() operation • Creation of an instance of a metaclass

Page 13: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 13 - © 2006 LIP6

RefObject

• Specialization of RefFeatured

• Represents the notion of an element that is an instance of a metaclass

• Offers the refIsInstance() operation • Check whether this element is the instance of a given

metaclass

Page 14: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 14 - © 2006 LIP6

RefAssociation

• Specialization of RefBaseObject

• Represents the notion of links between elements (i.e. RefObjects)

• Offers the refAddLink()and refRemoveLink()operations• Add and Remove links between elements

Page 15: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 15 - © 2006 LIP6

RefPackage

• Specialization of RefBaseObject

• Represents the notion of package (container of metaclasses).

• Offers the refGetClass() operation • List of the metaclasses (RefClass) contained in the

package

Page 16: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 16 - © 2006 LIP6

Example : the Use Case Diagram (UCD)

Construction of a model M(instance of a metamodel)

Page 17: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 17 - © 2006 LIP6

The UCD metamodel and the model M

A model M compliant to UCD

The UCD metamodel

case

Page 18: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 18 - © 2006 LIP6

Construction of the model M

• With the reflective interfaces (without generating the metamodel-specific API)

• Writing the program that creates the model by using directly the operations of the reflective interfaces

• Need the implementation of the reflective interfaces (such as ModFact*, MDR*)• Bootstrapping application (i.e. obtaining the instance of

RefPackage): implementation-specific mechanism

* See references

Page 19: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 19 - © 2006 LIP6

Construction of the model M

[1] RefPackage p = //proprietary mechanism[2] RefObject act =

p.refClass("Actor").refCreateInstance(null);[3] act.refSetValue("name","Client");[4] RefObject ca1 = p.refClass("UseCase").refCreateInstance(null);[5] ca1.refSetValue("title","CartOrder");[6] RefObject ca2 = p.refClass(" UseCase").refCreateInstance(null);[7]ca2.refSetValue("title","CartValidation");[8]Collection col = (Collection) act.refGetValue("participate");[9]col.add(ca1);[10]col.add(ca2);[11]RefObject sys = p.refClass("System").refCreateInstance(null);[12]sys.refSetValue("name","PetStore");[13]Collection cas = (Collection) sys.refGetValue("case");[14]cas.add(ca1);[15]cas.add(ca2);

Page 20: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 20 - © 2006 LIP6

The Tailored Interfaces

•Offer dedicated operations for handling models that are instances of a particular metamodel

•Example : operations for handling UCD models (instances of the UCD metamodel)

Page 21: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 21 - © 2006 LIP6

Navigation

• The tailored interfaces generated for the UCD metamodel enable, for each UCD model:• To get the number of actors, use cases, systems

• To get the name of an actor (of a use case, of a system) and to modify it

• To get the inheritance links between actors and to modify them

• To get the use cases in which an actor participates and to modify them

• To add/remove a use case

• …

Page 22: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 22 - © 2006 LIP6

Generation Rules

• JMI1.0 defines the taylored interfaces generation from MOF1.4 metamodels

• Presentation of• Metaclass Rule

• Meta-association Rule

• Metapackage Rule

Page 23: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 23 - © 2006 LIP6

The metaclass Rule

• For a metaclass of a metamodel :TWO interfaces

• Instance Interface• Offers the operations to read/modify the instances of the

metaclass

• Factory Interface• Offers the operations to create the instances of the

metaclass

Page 24: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 24 - © 2006 LIP6

The Instance Interface

• Its name = name of the metaclass

• Offers the get/set operations for each meta-attribute of the metaclass• Ex. Setting the name of an Actor.

• Offers the operations of navigation for each metareference of the metaclass• Ex. Navigating from a UseCase to an Actor.

• Specialization of the reflective interface RefObject

Page 25: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 25 - © 2006 LIP6

The Factory Interface

• Its name : name_metaclassClass

• Offers the operations to create instances of the metaclass• Ex. Creating instances of Actor.

• Specialization of the reflective interface RefClass

Page 26: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 26 - © 2006 LIP6

The Meta-association Rule

• For a meta-association of a metamodel : ONE interface (Meta-association interface)

• Its name = name of the meta-association• Offers the operations to create links between the

instances of metaclasses • Ex. Linking the instances I1 and I2 with the meta-association A1.

• Offers the operations to navigate through the links• Ex. Obtaining I2 from I1.

• Specialization of the reflective interface RefAssociation

Page 27: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 27 - © 2006 LIP6

The Metapackage Rule

• For a package of a metamodel : ONE interface (Package interface)

• Its name = package name + suffix "Package"• Ex. "Ucd" + "Package" UcdPackage

• Offers the operations enabling to get all the Factory interfaces of the metaclasses in this metapackage• Ex. Getting Factories for the metaclasses Usecase, System, Actor.

• Offers the operations enabling to get all the Meta-association interfaces of this metapackage• Ex. Getting Assocation interfaces for the meta-associations "include",

"extend".

• Specialization of the reflective interface RefPackage

Page 28: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 28 - © 2006 LIP6

Example: the Use Case Diagram (UCD)

Generation of the tailored interfacesConstruction of the model M

Page 29: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 29 - © 2006 LIP6

List (1): Results of Metaclass Rule

• Actor.java• Generated from the metaclass Actor (Instance interface).• provides the operations: getName(), setName(), getParticipate()

• ActorClass.java• Generated from the metaclass Actor (Factory interface).• provides the operation: createActor()

• System.java• Generated from the metaclass System (Instance interface).• provides the operations: getName(), setName(), getUseCase()

• SystemClass.java • Generated from the metaclass System (Factory interface).

• provides the operation: createSystem()• UseCase.java

• Generated from the metaclass UseCase (Instance interface).• provides the operations: getTitle(), setTitle(), getInclude(), getExtend()

• UseCaseClass.java • Generated from the metaclass UseCase (Factory interface).• provides the operation: createUseCase()

Page 30: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 30 - © 2006 LIP6

List (2) : Results of Meta-association Rule

• AUseCaseSystem.java •Generated from the meta-association between the

metaclasses UseCase and System.

• AInheritActor.java•Generated from the meta-association on the metaclass Actor

(an Actor inherits another Actor).• AParticipateActor.java

•Generated from the meta-association between the metaclasses Use Case et Actor (an Actor participates in a UseCase).

• AIncludeUseCase.java•Generated from the meta-association on the metaclass Use Case (A UseCase includes another UseCase).

• AExtendUseCase.java•Generated from the meta-association on the metaclass Use Case (A UseCase extends another UseCase).

Page 31: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 31 - © 2006 LIP6

List (3) : Result of Metapackage Rule

•UcdPackage.java•Generated from the metapackage containing all these

metaclasses and meta-associations.•Has the following operations:

• Getting all Factory interfaces:• SystemClass getSystem()

• UseCaseClass getUseCase()

• ActorClass getActor()

• Getting all Meta-association interfaces:• AUseCaseSystem getAUseCaseSystem();

• AInheriteActor getAInheriteActor();

• …..

Page 32: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 32 - © 2006 LIP6

Construction of the model M

[1]UcdPackage extent = //proprietary mechanism

[2]System sys = extent.getSystem().createSystem("PetStore");

[3]Actor ac = extent.getActor().createActor("Client");

[4]UseCase ca = extent.getUseCase ().createUseCase ("CartOrder");

[5]UseCase ca2 = extent.getUseCase() .createUseCase("CartValidation");

[6]ac.getParticipate().add(ca);

[7]ac.getParticipate().add(ca2);

[8]sys.getUseCase().add(ca);

[9]sys.getUseCase().add(ca2);

Page 33: Java Metadata Interface © 2006 LIP6 - 1 - A presentation of JMI Java Metadata Interface LIP6, Laboratoire d'Informatique de Paris 6 8, rue du Capitaine.

Java Metadata Interface

- 33 - © 2006 LIP6

References

• White Papers• http://java.sun.com/products/jmi/

• Download JMI• http://java.sun.com/products/jmi/download.html

• http://packages.debian.org/unstable/libs/libgnujmi-java

• Repository• http://mdr.netbeans.org

• http://modfact.lip6.fr