Managing work products

 

Overview

Work products have several predefined mechanisms, such as "propagation", or "file management", which are supported by several methods that can be redefined.

 

A work product groups together a generator's set of features as well as its results.  Through a dialog box, a work product is used to define the attributes which are to be taken into account by the generator.  It is also used to execute the J methods and to manage files generated by the work product.

 

All work products specialize the MpGenProduct metaclass.

A work product can be associated to files which will be automatically moved or deleted when changes to the associated model occur.  For example, the deletion of a class in Objecteering brings about the deletion of the associated files (C++ sources).

 

 

Managing work product attributes

A work product contains attributes that can be modified in a dialog box.  In a J method, we sometimes need to access the attribute values of this work product for generation purposes.

 

MpGenProduct:getAttributeVal (in String Name)

This service is used to access the value of an attribute defined on a work product.

 

MpGenProduct:setAttributeVal (in String Name, in String Value)

This service is used to assign the value of an attribute defined on a work product.

 

 

Managing work product propagation

Very often, a work product of the same kind exists in a model tree structure.  Typically, a package can have a work product, which has equivalent elements for sub-packages and sub-classes.  Work product propagation is a useful facility for end users, who can carry out operations which will be propagated on the entire tree (for example, code generation).

The four following J methods must be defined on the UML profile which manages the MDAC and on the work product.

 

To adapt the management of work products (consistency and propagation on a model), as well as the management of the generated files, these methods must be redefined.

 

The ... method on the MpGenProduct metaclass

is automatically triggered on a work product when ...

initProduct (in MpGenProduct product)

it is managed for the first time.  When a work product is propagated to a model, the Product parameter corresponds to a "parent" work product.  The current work product can then be initialized according to the "parent" work product.

update (in MpGenProduct product)

this work product or its associated model element is modified.  The work product is therefore informed of the modifications that are carried out, provided it has been managed.  This method allows the user to manage the generated files according to the modifications made to the work product (different suffix, directory, etc.)

boolean mustPropagate ()

it is necessary to define until which model elements (facade package, package, or class), the propagation must continue.  Therefore, it is possible to avoid the propagating of a work product to the packages or classes depending on the model element that is related to the work product.  For example, if the work product that is being processed is related to a class, this method must return False if we do not wish to create a work product on a class automatically.

boolean isPresent (in MpGenProduct product)

It is necessary to know whether a similar work product should be created during the propagation.  This feature is used when a work product is already defined on a model element, but hasn't yet been managed.  In this case, it is not necessary to create this work product.

 

 

Retrieving a work product

When a model element is being generated, (package or class), you may need to know the generation work product with the same type defined on this element to recover the attributes that are specific to this work product.

 

A package generation work product can easily bring on the generation of the classes of this package.  It is then possible to retrieve the class' generation work product.

 

ModelElement:default#external#getAnyProduct()

MpGenProduct

This service is used to find the generation work product of the current element which is driving the current J execution.

 

 

Managing consistency and creation

initObject()

This is called on an element before its creation.

 

boolean verify()

This is called when the button "OK" is pressed to permit the product to close, especially to increase the consistency rules.

 

 

Managing generation templates

A work product can be associated to a document template or to a generation template.  The following methods are necessary for connecting these.

 

initTemplate (in String pName)

This relates a generation template to a product.  pName is the Name of the template that must be accessible in the product MDAC.

 

This method returns a boolean, as follows:

·         "false" if the generation template whose name has been used as a parameter is not found

·         "true" if the generation template whose name has been used as a parameter is found

 

String generateWithTemplate()

This generates with the generation template related to the product.

 

 

Example

MyProduct:default#external#Code#MyGen#initProduct

          (in MpGenProduct Product)

{

String ProductName;

String Suffix;

String Path;

 

   // opening of a session

   sessionBegin ("Propagate", true);

 

   if (notVoid (Product))

{

      // retrieval of the parent work product values

      ProductName = Product.Name;

      Path        = Product.getAttributeVal("path");

      Suffix      = Product.getAttributeVal("suffix");

 

      // initialization of the current work product

      setName (ProductName);

      setAttributeVal ("path", Path);

      setAttributeVal ("suffix", Suffix);

  

}

 

   // closing of the "Propagate" session

   sessionEnd ();

}

 

MyProduct:default#external#Code#MyGen#update

          (in MpGenProduct Product)

{

String ProductName;

String Suffix;

String Path;

 

   // opening of a session

   sessionBegin ("Propagate", true);

 

   if (notVoid (Product))

{

      // retrieval of the values of the parent work

         product

      ProductName = Product.Name;

      Path        = Product.getAttributeVal("path");

      Suffix      = Product.getAttributeVal("suffix");

 

      // initialization of the current work product

      setName (ProductName);

      setAttributeVal ("path", Path);

      setAttributeVal ("suffix", Suffix);

  

}

 

   // deletion of all the files managed by the work

      product

   deleteAllFiles ();

 

   // closing of the "Propagate" session

   sessionEnd ();

}

 

MyProduct:default#external#Code#MyGen#mustPropagate () return boolean

{

   // propagation is carried out on any model

   // element associated to the current work product

   // A similar work product will then be built for all

   // the packages and classes

   return true;

}

 

MyProduct:default#external#Code#MyGen#isPresent (Product : in MpGenProduct) return boolean

{

   // avoids having a work product with the same type

   // on a model element with the package or class type

   return Product.ClassOf==ClassOf;

  

}

 

Class:default#external#Code#MyGen#generateClass

{

MpGenProduct ClassProduct;

String Path;

 

   // returns the first work product found on

   // the class, with the defined "MyProduct" type

   // on the "default#Code#MyGen" MDAC

   ClassProduct = getAnyProduct ();

   Path = ClassProduct.getAttributeName("path");

  

   StdOut.write("The MyGen file of the class is generated in ");

   StdOut.write(Path, NL);

}