Hi,
I'm currently trying to make a documentation generation and I want to show
in my documentation each diagram and the components of a diagram:
FOREACH diagram
<diagramImage>
<table>
<diagramElements>
<table>
I'm using oAW like that:
I have a .xpt file :
«IMPORT uml»
«EXTENSION templates::modelUtil»
«DEFINE Root(String fileName) FOR Package»
«FILE fileName+".docbook"»
<?xml version='1.0' encoding="ISO-8859-15" ?>
<book lang="en">
«EXPAND PackageChapter FOREACH ownedElement»
</book>
«ENDFILE»
«ENDDEFINE»
«DEFINE PackageChapter FOR Package»
<chapter id="idPackage«name»">
«EXPAND InitList»
</chapter>
«EXPAND PackageChapter FOREACH this.ownedElement»
«ENDDEFINE»
«DEFINE InitList FOR Package»
<section>
«EXPAND Images(this) FOREACH
getAssociatedDiagrams(this)»
</section>
«ENDDEFINE»
«DEFINE Images(Package pack) FOR String»
«EXPAND ShowImageAndObjectsForDiagram(pack)»
«ENDDEFINE»
«DEFINE ShowImageAndObjectsForDiagram(Package pack) FOR String»
«IF !this.contains("Package")»
<para>
<mediaobject>
<imageobject>
<imagedata align="center"
fileref="«this»"/>
</imageobject>
</mediaobject>
</para>
<section>
«EXPAND ActorTableHeader(pack)»
</section>
<section>
«EXPAND UseCasesTableHeader(pack)»
</section>
«ENDIF»
«ENDDEFINE»
«DEFINE ActorTableHeader(Package pack) FOR String»
<table>
<title>Actors details</title>
<tgroup cols="2">
<thead>
<row>
<entry>Actor</entry>
<entry>Details</entry>
</row>
</thead>
<tbody>
«EXPAND ActorTemplate FOREACH
getAssociatedObjects(pack, this)»
</tbody>
</tgroup>
</table>
«ENDDEFINE»
«DEFINE ActorTemplate FOR Actor»
«EXPAND ActorTemplateContent»
«ENDDEFINE»
«DEFINE ActorTemplateContent FOR Actor»
«EXPAND ShowDoc(this) FOREACH eAnnotations.details»
«ENDDEFINE»
«DEFINE UseCasesTableHeader(Package pack) FOR String»
<table>
<title>Actors details</title>
<tgroup cols="2">
<thead>
<row>
<entry>UseCase</entry>
<entry>Details</entry>
</row>
</thead>
<tbody>
«EXPAND UseCasesTemplate FOREACH
getAssociatedObjects(pack, this)»
</tbody>
</tgroup>
</table>
«ENDDEFINE»
«DEFINE UseCasesTemplate FOR UseCase»
«EXPAND UseCasesTemplateContent»
«ENDDEFINE»
«DEFINE UseCasesTemplateContent FOR UseCase»
«EXPAND ShowDoc(this) FOREACH eAnnotations.details»
«ENDDEFINE»
«DEFINE ShowDoc(UseCase uc) FOR ecore::EStringToStringMapEntry»
<row>
<entry>«uc.name»</entry>
<entry>«value»</entry>
</row>
«ENDDEFINE»
«DEFINE ShowDoc(Actor act) FOR ecore::EStringToStringMapEntry»
<row>
<entry>«act.name»</entry>
<entry>«value»</entry>
</row>
«ENDDEFINE»
I've defined the getAssociatedObjects method in the .ext extension file:
import ecore;
import org::topcased::gendoc::model2docbook::GenHelper;
import org::topcased::gendoc::model2docbook::GenHelperCustom;
// An extension to get the list of all the diagrams exported images
List[String] getAssociatedDiagrams(EObject eObject) :
JAVA
org.topcased.model2doc.templates.openarchitectureware.GenHelper.getAssociatedDiagrams(org.eclipse.emf.ecore.EObject);
//An extension to get the list of all the objects for a specified
diagram
List[EObject] getAssociatedObjects(EObject eObject, String diagName) :
JAVA
org.topcased.model2doc.templates.openarchitectureware.GenHelperCustom.getAssociatedObjects(org.eclipse.emf.ecore.EObject,
java.lang.String);
And the method is implemented in the .java file:
package org.topcased.model2doc.templates.openarchitectureware;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.topcased.modeler.di.model.Diagram;
import org.topcased.modeler.diagrams.model.Diagrams;
import org.topcased.modeler.diagrams.model.util.DiagramsUtils;
public final class GenHelperCustom {
private GenHelperCustom()
{
}
public static List<EObject> getAssociatedObjects(EObject eObject,
String diagram)
{
List<Diagram> lstDiags = new ArrayList<Diagram>();
List<EObject> lstObj = new ArrayList<EObject>();
String diagNameWithoutExt = diagram.replaceAll(".gif",
"");
lstDiags = getDiagramsList(eObject);
for(Diagram diag : lstDiags)
{
if (diag.getName().equals(diagNameWithoutExt)) {
lstObj = diag.eContents();
return lstObj;
}
}
return new ArrayList<EObject>();
}
private static List<Diagram> getDiagramsList(EObject eObject)
{
// First : retrieve the model URI of the file associated with the
model element
URI modelURI = eObject.eResource().getURI();
ResourceSet resourceSet = eObject.eResource().getResourceSet();
// Second : retrieve the diagrams file if it exists
URI diagramsURI = URI.createURI(modelURI.toString().concat("di"));
IFile diagramsFile =
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(diagramsURI.toFileString()));
if (diagramsFile.exists())
{
// Third : retrieve all the Diagram elements associated with
the given model element
Resource diagramsResource =
resourceSet.getResource(diagramsURI, true);
Diagrams rootDiagrams = (Diagrams)
diagramsResource.getContents().get(0);
// Fourth : compute all the relativePaths to the images using
the Diagram name property
return DiagramsUtils.findAllExistingDiagram(rootDiagrams,
eObject);
}
return new ArrayList<Diagram>();
}
}
But when I try to generate the documentation, it makes an error.
I locate the error during the call to getAssociated diagram in the .xpt
file.
Maybe I can't use diag.eContents() to get the elements of the diagram but
I don't know how the retrive the elements of the diagram.
If someone have an idea or knows where is my mistake !!
Regards,
Arnaud_______________________________________________
Topcased-users mailing list
[email protected]
http://lists.gforge.enseeiht.fr/mailman/listinfo/topcased-users