astah* API User Guide


[How to get Model Information]

  1. How to get Model Information of Class Diagram
  2. How to get Model Information of Activity Diagram
  3. How to get Model Information of Sequence Diagram
  4. How to get Model Information of Statemachine Diagram
  5. How to get Model Information of Data Flow Diagram
  6. How to get Model Information of CRUD
  7. How to get Diagrams
  8. How to get Alias
  9. How to get Hyperlink
  10. How to get basic elements in Flowchart
  11. How to search models from ProjectAccessor
Please refer to astah* API JavaDoc for details of Interfaces and methods.

[How to get Model Information of Class Diagram]

How to get Attribute information of class

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.

How to get Operation information of class

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

How to get Dependency information of class

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 this figure.

How to get Realization information of class

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 this figure.

How to get Generalization information of class

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 this figure.

How to get Template Class of a class

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

How to get 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();
    }

[How to get Model Information of Activity Diagram]

How to get 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 this figure.

How to get 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.
For example, in case of two control flows, the information will be like this figure.

How to get 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.
For example, the information for actions0 and start point will be like this figure.

[How to get Model Information of Sequence Diagram]

How to get Lifeline

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

How to get CompoundFragment

Get the array of CombinedFragment (ICombinedFragment) and Message (IMessage) by calling getFragments() Method of Interaction(IInteraction).
For example, the information of alt compound fragment will be like this figure.

How to get Operand

Get the array of InteractionOperand (IInteractionOperand) by calling getInteractionOperands() Method of CombinedFragment(ICombinedFragment).
For example, the information of two compound fragments in alt compound fragment will be like this figure.

How to get Message

Get the array of CombinedFragment(ICombinedFragment) and Message (IMessage) by calling getFragments() Method of Interaction(IInteraction).
For example, the information of Message0 will be like this figure.

[How to get Model Information of Statemachine Diagram]

How to get 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).

How to get 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).

[How to get Model Information of Data Flow Diagram]

How to get 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).

How to get ExternalEntity

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

How to get DataStore

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

[How to get Model Information of CRUD]

How to get Header Cells

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

How to get Value Cells

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

[How to get Diagrams]

NamedElement (INamedElement) is the parent of diagram (IDiagram), package (IPackage) and partition (IPartition) etc.
All diagrams can be got 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 ;
}

[How to get Alias]

Alias is hold by taggedValue in a model.TaggedValues can be got 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;
}

[How to get Hyperlink]

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 got 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 a astah* model

[How to get basic elements in 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 list of basic elements

process1 (As standard process, there is no stereotype)
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)

[How to search models from ProjectAccessor]

There are three methods to search from ProjectAccessor.

public INamedElement[] findElements(Class elementKind, String name) throws ProjectNotFoundException;
Search by name and element kind. This search does not apply for presentations such as ITopicPresentation.

Sample : 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();

public abstract INamedElement[] findElements(Class elementKind) throws ProjectNotFoundException;
Search elements by element type. 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();

public INamedElement[] findElements(ModelFinder picker) throws ProjectNotFoundException;
Search element by using ModelFinder.

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();


Home