Create Deployment Diagram using Open API

tomcat-thumbDeployment Diagram in Unified Modeling Language is helps to model the physical deployment structure of a software system. It helps to illustrate the structure how the hardware or software components (artifacts) exist in the system and how are they related to each other.. Instead of creating deployment diagram manually, you can also create it programmatically using Open API. In this article we will show you how to create the deployment diagram with Visual Paradigm’s Open API.

This is the deployment diagram which we are going to create. The diagram consists of a Node, 2 Artifacts, 2 Deployment Specification and 2 Dependency. Let’s start with create a blank deployment diagram.

Deployment Diagram which we are going to create via Open API

Deployment Diagram which we are going to create via Open API

Create Blank Deployment Diagram

Let’s start by create a blank diagram. We can use the DiagramManager.createDiagram operation to create a blank new diagram.

DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager();
IDeploymentDiagramUIModel diagram = (IDeploymentDiagramUIModel) diagramManager.createDiagram(IDiagramTypeConstants. DIAGRAM_TYPE_DEPLOYMENT_DIAGRAM);

Creating Node

Once the diagram is created, we can then move on to create the diagram element and model elements. Our diagram include a Node, Artifact and Deployment specification. Let’s start by create the Node. To create the Node.

// create the component model
// create node model
INode nodeModel = IModelElementFactory.instance().createNode();
nodeModel.setName("AppServer");
// create node shape on diagram
INodeUIModel nodeShape = (INodeUIModel) diagramManager.createDiagramElement(diagram, nodeModel);
// specify its location & dimension on diagram
nodeShape.setBounds(72, 111, 482, 285);
// set to automatic calculate the initial caption position
nodeShape.setRequestResetCaption(true);
Create AppServer Node in deployment Diagram

Create AppServer Node in deployment Diagram

Creating Artifact on Node

Next we go create the Artifacts. To create the Artifact:

// create Artifact model
IArtifact artifactShoppingAppEarModel = IModelElementFactory.instance().createArtifact();
artifactShoppingAppEarModel.setName("ShoppingApp.ear");
// add the artifact model as the child of node
nodeModel.addArtifact(artifactShoppingAppEarModel);
// create artifact shape on diagram
IArtifactUIModel artifactShoppingAppEarShape = (IArtifactUIModel) diagramManager.createDiagramElement(diagram, artifactShoppingAppEarModel);
artifactShoppingAppEarShape.setBounds(106, 176, 419, 190);
// specify the caption of the artifact shape at top middle
artifactShoppingAppEarShape.setModelElementNameAlignment(IShapeUIModel.MODEL_ELEMENT_NAME_ALIGNMENT_ALIGN_TOP_MIDDLE);
// make the artifact shape contained by the node shape
nodeShape.addChild(artifactShoppingAppEarShape);
artifactShoppingAppEarShape.setRequestResetCaption(true);

Again, now it’s your turn to create the second artifact.

Create Artifacts inside Node

Create Artifacts inside Node

Creating Deployment Specification

We got 2 Deployment Specification on our diagram, the ShoppingAppdesc.xml and Orderdesc.xml. Now let’s create them.

// create deployment specification model
IDeploymentSpecification depSpecShoppingAppdescXMLModel = IModelElementFactory.instance().createDeploymentSpecification();
depSpecShoppingAppdescXMLModel.setName("ShoppingAppdesc.xml");
// add the deployment specification model as child of artifact model
artifactShoppingAppEarModel.addDeploymentSpecification(depSpecShoppingAppdescXMLModel);
// create deployment specification shape
IDeploymentSpecificationUIModel depSpecShoppingAppdescXMLShape = (IDeploymentSpecificationUIModel) diagramManager.createDiagramElement(diagram, depSpecShoppingAppdescXMLModel);
depSpecShoppingAppdescXMLShape.setBounds(126, 307, 130, 40);
// make the artifact shape contain the deployment specification shape
artifactShoppingAppEarShape.addChild(depSpecShoppingAppdescXMLShape);
depSpecShoppingAppdescXMLShape.setRequestResetCaption(true);

Try follow the above to create the second Deployment Specification, the Orderdesc.xml.

Create Deployment Specification inside Artifact

Create Deployment Specification inside Artifact

Creating Dependency

Finally we come to create the relationships. In the deployment diagram we have 2 dependency relationship, from Shopping.jar to Order.jar, and from Orderdesc.xml to Order.jar. To create the dependency from Shopping.jar to Order.jar:

// create dependency model between Shopping.jar & Order.jar
IDependency dependencyShoppingJarOrderJar = IModelElementFactory.instance().createDependency();
// specify the from end (supplier)
dependencyShoppingJarOrderJar.setFrom(artifactShoppingJar);
// specify the to end (client)
dependencyShoppingJarOrderJar.setTo(artifactOrderJar);
// create dependency connector on diagram
diagramManager.createConnector(diagram, dependencyShoppingJarOrderJar, artifactShoppingJarShape, artifactOrderJarShape, new Point[] {new Point(247, 239), new Point(373, 239)});

Once again, follow the above to create the other dependency on the diagram.

Create dependency between Artifacts and Deployment Specification

Create dependency between Artifacts and Deployment Specification

Show up the diagram

When everything is ready we can show up the diagram.

diagramManager.openDiagram(diagram)

Sample Plugin

The sample plugin attached in this article demonstrate how to create deployment diagram using Open API. After you deploy the plugin into Visual Paradigm, you can then click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Trigger sample plugin

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply