Getting model information

  1. Class Diagram
  2. Activity Diagram
  3. Sequence Diagram
  4. Statemachine Diagram
  5. Data Flow Diagram
  6. Flowchart
  7. CRUD
  8. Diagrams
  9. Alias
  10. Hyperlink
  11. Search models from ProjectAccessor

Class Diagram

Attribute

Get the array of Attributes by calling Class (IClass) Method getAttributes().
If the class is associated with other classes, the information of the association end will be included in Attribute information objects.
For example, if Class0 has attribute0 and is associated with Class1 (association end role name class1), the attribute information of Class0 will be shown like this figure below.

Responsive image

Operation

Get the array of Operations by calling Class (IClass) Method getOperations().

Dependency

Get the array of all Dependencies of the selected class by calling Class (IClass) Method getClientDependencies().
By calling getSupplier(), you can get the supplier class of the selected class.
For example, in case that Class0 depends on Class1, the information will be shown like the figure below.

Responsive image

Realization

Get the array of Realizations between the selected class and the realized interfaces by calling Class (IClass) Method getClientRealizations().
By calling getSupplier(), you can get the realized interfaces. For example, in case that Class1 realizes Class0, the information will be shown like the figure below.

Responsive image

Generalization

Get the array of Generalizations between the selected class and its superclass by calling Class (IClass) Method getGeneralizations().
By calling getSuperType(), you can get its superclass information. For example, in case that Class1 inherits Class0, the information will be like the figure below.

Responsive image

Template Class of a class

Get the array of templateBindings (ITemplateBinding) by calling Class (IClass) Method getTemplateBindings().
By calling getTemplate() of templateBindings (ITemplateBinding), you can get its template class.

Template Parameter of a template class

Get the array of templateParameters (ITemplateParameter) by calling Class (IClass) Method getTemplateParameters().
By calling getTemplate() of templateBindings (ITemplateBinding), you can get its template class.

How to get a model of project accessor

All model information in Astah Project file is stored under the model of project accessor (Project model) in a tree structure.
First, get the ProjectAccessor object and open Astah project file, then get Project Model (IModel Class object).

ClassDefinitionBuilder.java
// Open project file and get project model
ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open(inputFile);
IModel iModel = prjAccessor.getProject();

How to get packages under Package recursively

It is defined that Package would include Subsystems and Models that inherit IPackage.
Get all model elements directly under the package (IPackage) in an array by calling getOwnedElements() and get only packages abstracted from it.

ClassDefinitionBuilder.java
 /**
  * Get packages under Package recursively.
  *
  * @param iPackage
  *     Selected Package
  * @param iPackages
  *     The list of all stored packages
  * @return The list of all stored packages
  */
  private List getPackages(IPackage iPackage, List iPackages) {
INamedElement[] iNamedElements = iPackage.getOwnedElements();
for (int i = 0; i < iNamedElements.length; i++) {
  INamedElement iNamedElement = iNamedElements[i];
  if (iNamedElement instanceof IPackage) {
iPackages.add(iNamedElement);
getPackages((IPackage)iNamedElement, iPackages);
  }
}
 return iPackages;
 }

How to get Classes under Package

Get all model elements directly under the package in an array by calling getOwnedElements() and get only classes abstracted from it.

ClassDefinitionBuilder.java
  /**
  * Get classes under the selected Package.
  *
  * @param iPackage
  *     Selected package
  * @return the list of all stored classes
  */
  private List getIClasses(IPackage iPackage) {
List iClasses = new ArrayList();
INamedElement[] iNamedElements = iPackage.getOwnedElements();
for (int i = 0; i < iNamedElements.length; i++) {
  INamedElement iNamedElement = iNamedElements[i];
  if (iNamedElement instanceof IClass) {
iClasses.add(iNamedElement);
  }
}
return iClasses;
  }

How to get Full Path Name of class

Get the name of class by calling getName() in case they are subclasses of INamedElement (i.g. IClass).
In addition, by calling getOwner() that obtains the owned model elements, the Full Path name from the project model can be obtained.

ClassDefinitionBuilder.java
  /**
    * Get the class name with Full Path
    *
    * @param iClass
    *     Class
    * @return Class name (Full Path)
    */
    private String getFullName(IClass iClass) {
StringBuffer sb = new StringBuffer();
IElement owner = iClass.getOwner();
while (owner != null && owner instanceof INamedElement && owner.getOwner() != null) {
  sb.insert(0, ((INamedElement) owner).getName() + "::");
  owner = owner.getOwner();
}
sb.append(iClass.getName());
return sb.toString();
  }


▶ Back to Top


Activity Diagram

Partition

Get the array of partitions (IPartition) by calling getPartitions() Method of IActivity.
By calling getSuperPartition() and getSuperPartition(), you can get hierarchy information of partitions.
For example, in case of Partition0 and Partition1, the information will be like the figure below. Responsive image

Control Flow

Get the array of control flow (IFlow) by calling getFlows() Method of IActivity.
By calling getIncomings() and getOutgoings(), you can get information of control flow of actions.

Actions and Start Point

Get the array of ActivityNode (IActivityNode) by calling getActivityNode() Method of IActivity.
By calling getActivityNode() of Partition (IPartition), you can get actions' information in a partition.


▶ Back to Top


Sequence Diagram

Lifeline

Get the array of Lifeline (ILifeline) by calling getLifelines() Method of Interaction(IInteraction).
For example, the information of LifeLine0 will be like the figure below. Responsive image

CombinedFragment

Get the array of CombinedFragment (ICombinedFragment) and Message (IMessage) by calling getFragments() Method of Interaction(IInteraction).

Operand

Get the array of InteractionOperand (IInteractionOperand) by calling getInteractionOperands() Method of CombinedFragment(ICombinedFragment).

Message

Get the array of CombinedFragment(ICombinedFragment) and Message (IMessage) by calling getFragments() Method of Interaction(IInteraction).


▶ Back to Top


Statemachine Diagram

State and SubmachineState

Get the statemachine (IStateMachine) by calling getStateMachine() Method of statemachine diagram (IStateMachineDiagram).
Get the state (IState) by calling getVertexes() Method of statemachine (IStateMachine).
Submachine state can be judged by isSubmachineState() of state (IState).

InitialPseudoState, DeepHistoryPseudoState, ForkPseudoState,etc

Get the statemachine (IStateMachine) by calling getStateMachine() Method of statemachine diagram (IStateMachineDiagram).
You can get the pseudoState (IPseudoState) by calling getVertexes() Method of statemachine (IStateMachine).
DeepHistoryPseudostate or forkPseudoState can be judged by isForkPseudostate() of state (IPseudoState).



▶ Back to Top


Data Flow Diagram

Process

Get the process (IProcessBox) by calling getDataFlowNodes() Method of dataFlow diagram (IDataFlowDiagram).
You can get the dataFlowDiagram(IDataFlowDiagram) of process by calling getDataFlowDiagram() Method of process(IProcessBox).

How to get DataFlow

Get the dataflow (IDataFlow) by calling getIncomings() Method and getOutgoings() of processBox (IProcessBox).

ExternalEntity

Get the external entity (IExternalEntity) by calling getDataFlowNodes() Method of dataFlowDiagram (IDataFlowDiagram).

DataStore

Get the dataStore (IDataStore) by calling getDataFlowNodes() Method of dataFlowDiagram (IDataFlowDiagram).



▶ Back to Top


Flowchart

Flowchart is a kind of activity diagram in Astah. Basic elements in a flowchart are action with stereotypes.

How to get loop start element
private static final String LOOP_START_ELEMENT = "loop_start";

public List getLoopStartElements(IActivityDiagram iActivityDiagram) {
  List loopStartElements = new ArrayList();

  IActivity iActivity = iActivityDiagram.getActivity();
  IActivityNode[] activityNodes = iActivity.getActivityNodes();
   for (int i = 0; i < activityNodes.length; i++) {
  IActivityNode node = activityNodes[i];
  String[] stereotypes = node.getStereotypes();
  for (int j = 0; j < stereotypes.length; j++) {
    if (LOOP_START_ELEMENT.equals(stereotypes[j])) {
  loopStartElements.add(node);
  break;
    }
  }
    }
    return loopStartElements;
}

Stereotype for basic elements

Model Stereotype
process1 N/A
process2 flow_process
Predefined Process predefined_process
Hand Work hand_work
Preparation preparation
Server server
Machine machine
Data data
Stored Data stored_data
Internal Storage internal_storage
Sequential Storage sequential_storage
Disk disk
Database database
Document document
Hand Inputting hand_inputting
Display display
Judgement judgement
Loop Start loop_start
Loop End loop_end
Internal Connector internal_connector
External Connector external_connector


▶ Back to Top


CRUD

Header Cells

Get the header cell (IHeaderCell) by calling getColumnHeaders() Method and getRowHeaders() Method of CRUD (IMatrixDiagram).

Value Cells

You can get the value cell (IValueCell) by calling getShowValueCell (row, column) Method of CRUD diagram (IMatrixDiagram).



▶ Back to Top


How to get Diagrams

NamedElement (INamedElement) is the parent of diagram (IDiagram), package (IPackage) and partition (IPartition) etc.
All diagrams can be gotten by getDiagrams() of an namedElement.

Example: How to get an activity diagram
public List getActivityDiagram(IPackage iPackage) {
  List activityDiagrams = new ArrayList();

  IDiagram[] dgms = iPackage.getDiagrams();
  for (int i = 0; i < dgms.length; i++) {
IDiagram dgm = dgms[i];
if (dgm instanceof IActivityDiagram
&& !((IActivityDiagram )dgm).isFlowChart()) {
  activityDiagrams.add(dgm);
 }
   }
  return activityDiagrams;
}
Example: How to get an sequence diagram
public List getFlowCharts(IPackage iPackage) {
  List flowCharts = new ArrayList();

  IDiagram[] dgms = iPackage.getDiagrams();
  for (int i = 0; i < dgms.length; i++) {
IDiagram dgm = dgms[i];
if (dgm instanceof IActivityDiagram
&& ((IActivityDiagram )dgm).isFlowChart()) {
   flowCharts.add(dgm);
 }
  }
  return flowCharts ;
}


▶ Back to Top


How to get Alias

Alias is hold by taggedValue in a model. TaggedValues can be gotten by ITaggedValue.
If key of alias1 is "jude.multi_language.alias1" and key of alias2 is "jude.multi_language.alias2", use the following codes:

Example: How to get alias1
 private static final String KEY_ALIAS1 = "jude.multi_language.alias1";

 private String geAlias1(INamedElement element) {
   ITaggedValue[] tvs = element.getTaggedValues();
   for (int i = 0; i < tvs.length; i++) {
 ITaggedValue tv = tvs[i];
 if (KEY_ALIAS1.equals(tv.getKey())) {
   return tv.getValue();
 }
   }
   return null;
}


▶ Back to Top


IHyperlinkOwner is generalized by INamedElement and IPresentation.
A list containing IHyperlinks of an IHyperlinkOwner can be got by getHyperlinks() method. 

Example for getting hyperlink
private void showHyperlinkStrings(INamedElement element) {

   IHyperlink[] links = element.getHyperlinks();
   for (int i = 0; i < links.length; i++) {
IHyperlink link = links[i];
if(link.isFile()) {
   System.out.println(link.getName());
   System.out.println(link.getPath());
   System.out.println(link.getComment());
} else if(link.isModel()) {
   System.out.println(link.getName());
   System.out.println(link.getPath());
   System.out.println(link.getComment());
} else if(link.isURL()) {
   System.out.println(link.getName());
   System.out.println(link.getPath());
   System.out.println(link.getComment());
 }
   }
}

Name of a model is id which can be gotten by getId() of IElementImp.

Example: How to get hyperlink
type=file,name=astah_com.log,path=C:/Documents and Settings,comment= Target is a file
type=url,name=http://www.change-vision.com,path=http://,comment= Target is a web page
type=model,name=9a1411-1112fec29a5-0804d01aa6c5fb9fe2aab956b4ca593a,path=,comment= Target is Astah model


▶ Back to Top


There are three methods to search from ProjectAccessor.

1. Search by name and element kind

public INamedElement[] findElements(Class elementKind, String name) throws ProjectNotFoundException;
  • ※This search does not apply for presentations such as ITopicPresentation.
Example : findElements(Class elementKind, String name)
ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asta");
//Search a class diagram named classDgm0
INamedElement[] iNamedElements = prjAccessor.findElements(IClassDiagram.class, "classDgm0");
//Search a Class named A
iNamedElements = prjAccessor.findElements(IClass.class, "A");
//Search an attribute named B
iNamedElements = prjAccessor.findElements(IAttribute.class, "B");
//Search an operation named C
iNamedElements = prjAccessor.findElements(IOperation.class, "C");
//Search an association named D

iNamedElements = prjAccessor.findElements(IAssociation.class, "D");
//Search an UseCase named E
iNamedElements = prjAccessor.findElements(IUseCase.class, "E");
//Search an Include named F
iNamedElements = prjAccessor.findElements(IInclude.class, "F");

//Search a state named G
iNamedElements = prjAccessor.findElements(IState.class, "G");
//Search a pseudostate named H
iNamedElements = prjAccessor.findElements(IPseudostate.class, "H");
//Search a transition named I
iNamedElements = prjAccessor.findElements(ITransition.class, "I");

//Search a partition named J
iNamedElements = prjAccessor.findElements(IPartition.class, "J");
//Search an action named K
iNamedElements = prjAccessor.findElements(IAction.class, "K");
//Search an objectnode named L
iNamedElements = prjAccessor.findElements(IObjectNode.class, "L");
//Search a flow named M
iNamedElements = prjAccessor.findElements(IFlow.class, "M");

//Search a lifeline named N
iNamedElements = prjAccessor.findElements(ILifeline.class, "N");
//Search a message named O
iNamedElements = prjAccessor.findElements(IMessage.class, "O");

//Search an External entity named P
iNamedElements = prjAccessor.findElements(IExternalEntity.class, "P");
//Search a datastore named Q
iNamedElements = prjAccessor.findElements(IDataStore.class, "Q");

//Search an ER model named R
iNamedElements = prjAccessor.findElements(IERModel.class, "R");
//Search an ERdomain named S
iNamedElements = prjAccessor.findElements(IERDomain.class, "S");
//Search an ER data type named USER_DEFINED_DATATYPE1
iNamedElements = prjAccessor.findElements(IERDatatype.class, "USER_DEFINED_DATATYPE1");
//Search an ER Entity named T
iNamedElements = prjAccessor.findElements(IEREntity.class, "T");
//Search an ER attribute named U
iNamedElements = prjAccessor.findElements(IERAttribute.class, "U");
//Search an ER relationship named V
iNamedElements = prjAccessor.findElements(IERRelationship.class, "V");
//Search an ERsubtype relationship named W
iNamedElements = prjAccessor.findElements(IERSubtypeRelationship.class, "W");
//Search an ER index named X
iNamedElements = prjAccessor.findElements(IERIndex.class, "X");

prjAccessor.close();

2. Search element type

public abstract INamedElement[] findElements(Class elementKind) throws ProjectNotFoundException;
  • ※This search does not apply for presentations such as ITopicPresentation.
Example : Search a class diagram named classDgm0 by using findElements(Class elementKind)
ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asta");
//Search a class diagram
INamedElement[] iNamedElements = prjAccessor.findElements(IClassDiagram.class);
prjAccessor.close();

3. Search by using ModelFinder

public INamedElement[] findElements(ModelFinder picker) throws ProjectNotFoundException;
  • ※This search does not apply for presentations such as ITopicPresentation.
Example : Search by using findElements(ModelFinder picker)
//A class that implements ModelFinder interface which extracts Class diagram
class ClassDiagramPicker implements ModelFinder {
public boolean isTarget(INamedElement namedElement) {
    if (namedElement instanceof IClassDiagram) {
       return true;
    }
    return false;
  }
}

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asta");
//Search a class diagram named classDgm0
INamedElement[] iNamedElements = prjAccessor.findElements(new ClassDiagramPicker());
prjAccessor.close();


▶ Back to Top