GSN
ファセットへアクセスする
GSNの全モデル、プレゼンテーションは、GSNファセットを表すモデル(以下、ファセットモデル)の下に存在します。
GSNファセットモデルは、ProjectAccessorからgetFacet(String symbolicName)を用いて取得します。
public IFacet getGSNFacet(ProjectAccessor projectAccessor) throws ProjectNotFoundException {
return projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
}モデル / プレゼンテーションの参照
モデルの参照
ArgumentAsset間のRelationshipを取得する
astah*上で下図のようなGSN図があり、GoalからContextへのInContextOfを取得するとします。

この場合、astah*のプロジェクト内のモデルは下図のようになります。

GoadやContext,InContextOfなどは、ArgumentAssetを継承しています。

public IArgumentAsset getInContextOfTarget(IArgumentAsset argumentAsset) throws ClassNotFoundException {
IFacet facet = AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IModule rootElement = facet.getRootElement(IModule.class);
for (IArgumentationElement argumentationElement : rootElement.getArgumentationElements()) {
if (argumentationElement instanceof IInContextOf
&& ((IInContextOf) argumentationElement).getSource() == argumentAsset) {
return ((IInContextOf) argumentationElement).getTarget();
}
}
return null;
}IArgumentAssetのIDとContentを取得する
GoalやStrategyなどのモデル構造を示します。GoalやStrategyなどは、ArgumentAssetを継承しています。
下記を参考にしてモデルを取得して下さい。

public String getIdentifier(IArgumentAsset argumentAsset){
return argumentAsset.getIdentifier();
}public String getContent(IArgumentAsset argumentAsset) {
return argumentAsset.getContent();
}図 / プレゼンテーションの参照
GSN図を取得する
public List<IGsnDiagram> getDiagrams() throws ClassNotFoundException {
IFacet facet = AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IModule rootElement = facet.getRootElement(IModule.class);
return getGSNDiagrams(rootElement, new ArrayList<IGsnDiagram>());
}
public List<IGsnDiagram> getGSNDiagrams(IModule module, List<IGsnDiagram> gsnDiagrams) {
for (IDiagram diagram : module.getDiagrams()) {
if (diagram instanceof IGsnDiagram) {
gsnDiagrams.add((IGsnDiagram) diagram);
}
}
for (IArgumentationElement argumentationElement : module.getArgumentationElements()) {
if (argumentationElement instanceof IModule) {
getGSNDiagrams((IModule) argumentationElement, gsnDiagrams);
}
}
return gsnDiagrams;
}図上で選択しているModuleにネストするSolutionのプレゼンテーションを取得する
astah*上で下図のようなGSN図があり、ModuleからネストするStrategyのプレゼンテーションを取得するとします。

INodePresentation.getChildrenからModuleにネストするStrategyを取得できます。
public INodePresentation[] getChildrenStrategiesPresentation(IGsnDiagram gsnDiagram) throws InvalidUsingException {
for (IPresentation presentation : gsnDiagram.getPresentations()) {
IElement model = presentation.getModel();
if (presentation instanceof INodePresentation && model instanceof IModule
&& "parent module".equals(((IModule) model).getName())) {
return Stream.of(((INodePresentation) presentation).getChildren())
.filter(child -> child.getModel() instanceof IStrategy)
.toArray(INodePresentation[]::new);
}
}
return new INodePresentation[0];
}モデル / プレゼンテーションの編集
編集を行う場合は必ずトランザクション処理が必要となります。
なお、下記条件を満たしていない場合は例外が発生します。
プロジェクトアクセサにプロジェクトを登録していること
編集APIが対応しているエディションであること
対象が編集可能であること
モデルの編集
モデルエディタ
GSN関連モデルの編集はモデルエディタ(GsnModelEditor)を使用して行います。
例えば、SupportedByの作成はGsnModelEditorから作成できます。
モデルとプレゼンテーションが1:nで対応するモデルはモデルエディタから作成できます。

| モデルエディタの種類 | 作成可能要素 |
|---|---|
| GsnModelEditor | Goal、Strategy、Solution、Context、Justification、Assumption、Module、SupportedBy、InContextOf |
Goalを作成する
// 要トランザクション処理
public IGoal createGoal(ProjectAccessor projectAccessor) throws InvalidEditingException {
IModelEditorFactory modelEditorFactory = projectAccessor.getModelEditorFactory();
GsnModelEditor modelEditor = modelEditorFactory.getModelEditor(GsnModelEditor.class);
IFacet facet = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IModule module = facet.getRootElement(IModule.class);
return modelEditor.createGoal(module, "Goal1");
}SupportedByを作成する
// 要トランザクション処理
public ISupportedBy createSupportedBy(ProjectAccessor projectAccessor) throws InvalidEditingException {
IModelEditorFactory modelEditorFactory = projectAccessor.getModelEditorFactory();
GsnModelEditor modelEditor = modelEditorFactory.getModelEditor(GsnModelEditor.class);
IFacet facet = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IModule module = facet.getRootElement(IModule.class);
IArgumentAsset source = modelEditor.createGoal(module, "Source");
IArgumentAsset target = modelEditor.createStrategy(module, "Target");
return modelEditor.createSupportedBy(source, target);
}図 / プレゼンテーションの編集
ダイアグラムエディタ
図、プレゼンテーションの作成や削除はGsnDiagramEditorを使用して行います。
GsnDiagramEditorを以下のように取得できます。
ProjectAccessor projectAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);GSN図を作成する
// 要トランザクション処理
public IGsnDiagram createGsnDiagram(ProjectAccessor projectAccessor) throws InvalidUsingException, InvalidEditingException {
IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
IFacet facet = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IModule module = facet.getRootElement(IModule.class);
return diagramEditor.createGsnDiagram(module, "test");
}ModuleにネストするJustificationを作成する
// 要トランザクション処理
public INodePresentation createNestNodePresentation(GsnDiagramEditor editor, IModule module, IJustification justification, Point2D location) throws InvalidEditingException {
INodePresentation parentNodePresentation = createNodePresentation(editor, module, location);
return editor.createNodePresentation(justification, parentNodePresentation, location);
}
// 要トランザクション処理
public INodePresentation createNodePresentation(GsnDiagramEditor editor, IModule module,
Point2D location) throws InvalidEditingException {
return editor.createNodePresentation(module, location);
}図を削除する
// 要トランザクション処理
public void deleteGSNDiagram(IGsnDiagram gsnDiagram)
throws InvalidUsingException, ClassNotFoundException, InvalidEditingException {
ProjectAccessor projectAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
diagramEditor.delete(gsnDiagram);
}対応モデル / プレゼンテーション一覧
構造の詳細については、JavadocのGSN Overviewをご覧ください。
対応モデル一覧
| モデル | 型 | 参照 | 編集 | 作成メソッド |
|---|---|---|---|---|
| GSN図 | IGsnDiagram | ○ | ○ | createGsnDiagram(IModule, String) |
| Goal | IGoal | ○ | ○ | createGoal(IModule, String) |
| Strategy | IStrategy | ○ | ○ | createStrategy(IModule, String) |
| Solution | ISolution | ○ | ○ | createSolution(IModule, String) |
| Context | IContext | ○ | ○ | createContext(IModule, String) |
| Justification | IJustification | ○ | ○ | createJustification(IModule, String) |
| Assumption | IAssumption | ○ | ○ | createAssumption(IModule, String) |
| Module | IModule | ○ | ○ | createModule(IModule, String) |
| SupportedBy | ISupportedBy | ○ | ○ | createSupportedBy(IArgumentAsset, IArgumentAsset) |
| InContextOf | IInContextOf | ○ | ○ | createInContextOf (IArgumentAsset, IArgumentAsset) |
対応プレゼンテーション一覧
astah*のモデルに対応するプレゼンテーションの一覧です。
プレゼンテーションへの参照・編集の可否についてはastah* APIのAPIに対応する図要素一覧をご覧ください。
GSN / D-Case図
| 種別 | モデル | プレゼンテーションの型 | モデル:プレゼンテーション |
|---|---|---|---|
| Goal | IGoal | INodePresentation | 1対n |
| Strategy | IStrategy | INodePresentation | 1対n |
| Solution | ISolution | INodePresentation | 1対n |
| Context | IContext | INodePresentation | 1対n |
| Solution | ISolution | INodePresentation | 1対n |
| Justification | IJustification | INodePresentation | 1対n |
| Assumption | IAssumption | INodePresentation | 1対n |
| Module | IModule | INodePresentation | 1対n |
| SupportedBy | ISupportedBy | ILinkPresentation | 1対n |
| InContextOf | IInContextOf | ILinkPresentation | 1対n |