Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "MoDisco/Components/FacetManager/Documentation/0.8"
(Rename "role" to "facet") |
|||
Line 1: | Line 1: | ||
{{MoDiscoFacetManagerTabs}} | {{MoDiscoFacetManagerTabs}} | ||
− | ==How to create a model | + | ==How to create a model facet set== |
The first step is to [[MoDisco/ProjectNature|create | The first step is to [[MoDisco/ProjectNature|create | ||
a MoDisco project]]. | a MoDisco project]]. | ||
Line 7: | Line 7: | ||
The second step is to [[MoDisco/QueryManager|create | The second step is to [[MoDisco/QueryManager|create | ||
a query set]]. This query set will store boolean queries indicating if an | a query set]]. This query set will store boolean queries indicating if an | ||
− | object conforms to a | + | object conforms to a facet. |
Right-click on the MoDisco project and select the "New > Other | Right-click on the MoDisco project and select the "New > Other | ||
Line 14: | Line 14: | ||
[[Image:MoDisco_Role_newRoleSet_001.gif]] | [[Image:MoDisco_Role_newRoleSet_001.gif]] | ||
− | Select " | + | Select "Facet Model" and press the "Next" button |
[[Image:MoDisco_Role_newRoleSet_002.gif]] | [[Image:MoDisco_Role_newRoleSet_002.gif]] | ||
− | Choose a name for your model | + | Choose a name for your model facet set (My.facetSet in the example) |
and press "Next". | and press "Next". | ||
Line 24: | Line 24: | ||
− | Select " | + | Select "FacetSet" in the "Model Object" list and press "Finish" |
[[Image:MoDisco_Role_newRoleSet_004.gif]] | [[Image:MoDisco_Role_newRoleSet_004.gif]] | ||
Line 30: | Line 30: | ||
[[Image:MoDisco_Role_newRoleSet_005.gif]] | [[Image:MoDisco_Role_newRoleSet_005.gif]] | ||
− | Open the "My. | + | Open the "My.facetSet" file and open the "Properties View" |
[[Image:MoDisco_Role_newRoleSet_006.gif]] | [[Image:MoDisco_Role_newRoleSet_006.gif]] | ||
− | Set the name of the | + | Set the name of the facet set and make sure that the facet set name |
is the same as the containing file name ("My" in the example). The | is the same as the containing file name ("My" in the example). The | ||
nsURI and prefix must also be filled. | nsURI and prefix must also be filled. | ||
Line 41: | Line 41: | ||
Load the resources containing the meta-model extended by the | Load the resources containing the meta-model extended by the | ||
− | + | facet set. To load a meta-model resource the user must use the "Load | |
meta-model resource" action. | meta-model resource" action. | ||
Line 55: | Line 55: | ||
[[Image:MoDisco_Role_newRoleSet_010.gif]] | [[Image:MoDisco_Role_newRoleSet_010.gif]] | ||
− | Right click on the | + | Right click on the FacetSet element and choose the "New Child > Facet" |
− | action to create a | + | action to create a facet. |
[[Image:MoDisco_Role_newRoleSet_011.gif]] | [[Image:MoDisco_Role_newRoleSet_011.gif]] | ||
− | Set the | + | Set the facet name and the class that the facet will extend. |
[[Image:MoDisco_Role_newRoleSet_012.gif]] | [[Image:MoDisco_Role_newRoleSet_012.gif]] | ||
− | To specify how to know if an object conforms to a | + | To specify how to know if an object conforms to a facet, we have |
to provide a boolean query. To provide this query we have to load the | to provide a boolean query. To provide this query we have to load the | ||
model containing its description. | model containing its description. | ||
Line 77: | Line 77: | ||
Once the query set resource is referenced, we just have to select the | Once the query set resource is referenced, we just have to select the | ||
− | query describing the | + | query describing the facet. In the example this query is named |
"isAbstract". | "isAbstract". | ||
Line 83: | Line 83: | ||
At this step, if we save the model, the "red cross" should disappear | At this step, if we save the model, the "red cross" should disappear | ||
− | from the file icon. This means that the | + | from the file icon. This means that the facet set model is now valid. |
[[Image:MoDisco_Role_newRoleSet_016.gif]] | [[Image:MoDisco_Role_newRoleSet_016.gif]] | ||
− | If the | + | If the facet has specific attributes or references which can be |
calculated, we can declare them. In this example, we will declare an | calculated, we can declare them. In this example, we will declare an | ||
attribute indicating the number of abstract methods contained in the | attribute indicating the number of abstract methods contained in the | ||
− | abstract class. To create a new | + | abstract class. To create a new facet attribute right-click on the facet |
− | element and select the "New Child > | + | element and select the "New Child > FacetAttribute" item. |
[[Image:MoDisco_Role_newRoleSet_017.gif]] | [[Image:MoDisco_Role_newRoleSet_017.gif]] | ||
Line 103: | Line 103: | ||
− | The | + | The facet set is now ready to be used. |
− | == How to consult the MoDisco | + | == How to consult the MoDisco facet set catalog through the UI == |
− | If a | + | If a facet set model is valid, it is registered in the facet set |
− | catalog. To consult the | + | catalog. To consult the facet set catalog, we can use the "Facet Set" |
view. | view. | ||
To open this view select "Windows > Show view > Other ..." | To open this view select "Windows > Show view > Other ..." | ||
− | in the menu bar and choose " | + | in the menu bar and choose "Facet Set" in the list. |
[[Image:MoDisco_Role_newRoleSet_019.gif]] | [[Image:MoDisco_Role_newRoleSet_019.gif]] | ||
[[Image:MoDisco_Role_newRoleSet_020.gif]] | [[Image:MoDisco_Role_newRoleSet_020.gif]] | ||
− | The " | + | The "Facet set" view presents the available facet sets and their |
− | + | facets. For each facet set the location of its description model is pointed out. | |
[[Image:MoDisco_Role_newRoleSet_021.gif]] | [[Image:MoDisco_Role_newRoleSet_021.gif]] | ||
− | == How to programmatically use the MoDisco | + | == How to programmatically use the MoDisco facet set catalog == |
− | Here is an example of using the MoDisco | + | Here is an example of using the MoDisco facet API. For more information please refer to the JavaDoc. |
import org.eclipse.emf.ecore.EObject; | import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.gmt.modisco.infra.query.core.exception.ModelQueryException; | import org.eclipse.gmt.modisco.infra.query.core.exception.ModelQueryException; | ||
− | import org.eclipse.gmt.modisco.infra. | + | import org.eclipse.gmt.modisco.infra.facet.Facet; |
− | import org.eclipse.gmt.modisco.infra. | + | import org.eclipse.gmt.modisco.infra.facet.FacetSet; |
− | import org.eclipse.gmt.modisco.infra. | + | import org.eclipse.gmt.modisco.infra.facet.core.FacetSetCatalog; |
− | import org.eclipse.gmt.modisco.infra. | + | import org.eclipse.gmt.modisco.infra.facet.core.exception.ModiscoFacetException; |
− | + | ||
public class Example { | public class Example { | ||
public Integer getNbAbstractMethod(EObject eObject) | public Integer getNbAbstractMethod(EObject eObject) | ||
− | throws ModelQueryException, | + | throws ModelQueryException, ModiscoFacetException { |
− | + | FacetSet facetSet = FacetSetCatalog.getSingleton().getFacetSet("My"); | |
− | + | FacetContext context = new FacetContext(); | |
− | context. | + | context.addFacetSet(facetSet); |
− | + | Facet facet = facetSet.getFacet("AbstractClassDeclaration"); | |
− | if (context.isInstance(eObject, | + | if (context.isInstance(eObject, facet)) { |
− | Object object = context.get(eObject, | + | Object object = context.get(eObject, facet |
.getEStructuralFeature("nbAbstractMethod")); | .getEStructuralFeature("nbAbstractMethod")); | ||
if (object instanceof Integer) { | if (object instanceof Integer) { | ||
Line 154: | Line 153: | ||
} | } | ||
− | == | + | == Facet Meta-model Description == |
[[Image:MoDisco_Role_metamodel.png]] | [[Image:MoDisco_Role_metamodel.png]] | ||
− | The | + | The facet meta-model extends the ecore meta-model and uses the query meta-model. |
− | A | + | A FacetSet is a kind of EPackage. A FacetSet contains facets through |
− | the eClassifier reference. A | + | the eClassifier reference. A facet is a kind of EClass. |
− | For a | + | For a facet instance, the eSuperType reference must be set to |
− | specify which class the | + | specify which class the facet virtually extends. |
− | The | + | The facet class has one specific reference: conditionQuery. The |
conditionQuery reference points to the ModelQuery class. The model queries | conditionQuery reference points to the ModelQuery class. The model queries | ||
pointed to by the conditionQuery reference must return a Boolean. Those | pointed to by the conditionQuery reference must return a Boolean. Those | ||
queries are used to specify how to decide whether an instance conforms to a | queries are used to specify how to decide whether an instance conforms to a | ||
− | + | facet. If the conditionQuery is empty then all the instances of the class | |
− | referred to by the | + | referred to by the facet instance through the eSuperType reference conform |
− | to this | + | to this facet. |
− | A | + | A facet contains facetAttributes and facetReferences through the |
− | eStructuralFeature reference. The | + | eStructuralFeature reference. The FacetAttribute and FacetReference |
− | classes have a common super class: | + | classes have a common super class: FacetStructuralFeature. The |
− | + | FacetStructuralFeature has one reference named valueQuery pointing to | |
− | the ModelQuery class. The valueQuery is used to compute the | + | the ModelQuery class. The valueQuery is used to compute the facet |
− | structural feature value. The | + | structural feature value. The facetAttribute and facetReference must have |
the same type as the query they refer to. | the same type as the query they refer to. | ||
[[Category:MoDisco]] | [[Category:MoDisco]] |
Revision as of 06:31, 22 January 2010
DEPRECATED use Template:MoDiscoTabs and Template:MoDiscoTab as explain here : Wiki Template for MoDisco
Contents
How to create a model facet set
The first step is to create a MoDisco project.
The second step is to create a query set. This query set will store boolean queries indicating if an object conforms to a facet.
Right-click on the MoDisco project and select the "New > Other ..." button.
Select "Facet Model" and press the "Next" button
Choose a name for your model facet set (My.facetSet in the example) and press "Next".
Select "FacetSet" in the "Model Object" list and press "Finish"
Open the "My.facetSet" file and open the "Properties View"
Set the name of the facet set and make sure that the facet set name is the same as the containing file name ("My" in the example). The nsURI and prefix must also be filled.
Load the resources containing the meta-model extended by the facet set. To load a meta-model resource the user must use the "Load meta-model resource" action.
In this example, we choose to use the Java meta-model.
Fill the "Extended package" field with the ePackages containing the virtually extended meta-model.
Right click on the FacetSet element and choose the "New Child > Facet" action to create a facet.
Set the facet name and the class that the facet will extend.
To specify how to know if an object conforms to a facet, we have to provide a boolean query. To provide this query we have to load the model containing its description.
The query has to be referred to using the MoDisco protocol: "modisco:/query/<querySetName>". In the example, we use the "My" query set.
Once the query set resource is referenced, we just have to select the query describing the facet. In the example this query is named "isAbstract".
At this step, if we save the model, the "red cross" should disappear from the file icon. This means that the facet set model is now valid.
If the facet has specific attributes or references which can be calculated, we can declare them. In this example, we will declare an attribute indicating the number of abstract methods contained in the abstract class. To create a new facet attribute right-click on the facet element and select the "New Child > FacetAttribute" item.
The attribute's type and name must be set. The "Value Query" field must be filled with a reference to a query which is used to calculate the attribute's value. This query must have the same type as the attribute and be applicable to the virtually extended class.
The facet set is now ready to be used.
How to consult the MoDisco facet set catalog through the UI
If a facet set model is valid, it is registered in the facet set catalog. To consult the facet set catalog, we can use the "Facet Set" view.
To open this view select "Windows > Show view > Other ..." in the menu bar and choose "Facet Set" in the list.
File:MoDisco Role newRoleSet 020.gif
The "Facet set" view presents the available facet sets and their facets. For each facet set the location of its description model is pointed out.
How to programmatically use the MoDisco facet set catalog
Here is an example of using the MoDisco facet API. For more information please refer to the JavaDoc.
import org.eclipse.emf.ecore.EObject; import org.eclipse.gmt.modisco.infra.query.core.exception.ModelQueryException; import org.eclipse.gmt.modisco.infra.facet.Facet; import org.eclipse.gmt.modisco.infra.facet.FacetSet; import org.eclipse.gmt.modisco.infra.facet.core.FacetSetCatalog; import org.eclipse.gmt.modisco.infra.facet.core.exception.ModiscoFacetException; public class Example { public Integer getNbAbstractMethod(EObject eObject) throws ModelQueryException, ModiscoFacetException { FacetSet facetSet = FacetSetCatalog.getSingleton().getFacetSet("My"); FacetContext context = new FacetContext(); context.addFacetSet(facetSet); Facet facet = facetSet.getFacet("AbstractClassDeclaration"); if (context.isInstance(eObject, facet)) { Object object = context.get(eObject, facet .getEStructuralFeature("nbAbstractMethod")); if (object instanceof Integer) { Integer nbAbstractMethod = (Integer) object; return nbAbstractMethod; } } return null; } }
Facet Meta-model Description
The facet meta-model extends the ecore meta-model and uses the query meta-model.
A FacetSet is a kind of EPackage. A FacetSet contains facets through the eClassifier reference. A facet is a kind of EClass.
For a facet instance, the eSuperType reference must be set to specify which class the facet virtually extends.
The facet class has one specific reference: conditionQuery. The conditionQuery reference points to the ModelQuery class. The model queries pointed to by the conditionQuery reference must return a Boolean. Those queries are used to specify how to decide whether an instance conforms to a facet. If the conditionQuery is empty then all the instances of the class referred to by the facet instance through the eSuperType reference conform to this facet.
A facet contains facetAttributes and facetReferences through the eStructuralFeature reference. The FacetAttribute and FacetReference classes have a common super class: FacetStructuralFeature. The FacetStructuralFeature has one reference named valueQuery pointing to the ModelQuery class. The valueQuery is used to compute the facet structural feature value. The facetAttribute and facetReference must have the same type as the query they refer to.