Statistics
| Revision:

root / branches / modelio3.7.x / src / main / java / org / modelio / togaf / migration / migration37 / MigrationNoteParser.java @ 245

History | View | Annotate | Download (3.21 KB)

1
package org.modelio.togaf.migration.migration37;
2

    
3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.List;
6
import java.util.Set;
7
import org.modelio.metamodel.diagrams.AbstractDiagram;
8
import org.modelio.metamodel.uml.informationFlow.InformationFlow;
9
import org.modelio.metamodel.uml.infrastructure.Note;
10
import org.modelio.togaf.impl.TogafArchitectModule;
11

    
12
public class MigrationNoteParser {
13
    private List<MigrationDiagramNode> diagramNodes;
14

    
15
    private List<MigrationDiagramLink> diagramLinks;
16

    
17
    private List<MigrationInformationFlow> informationsflows;
18

    
19
    private Set<AbstractDiagram> diagrams;
20

    
21
    public MigrationNoteParser() {
22
        this.diagramNodes = new ArrayList<>();
23
        this.diagramLinks = new ArrayList<>();
24
        this.informationsflows = new ArrayList<>();
25
        this.diagrams = new HashSet<>();
26
    }
27

    
28
    public void pars(Note note) {
29
        String data = note.getContent();
30
        
31
        if (data.length() > 0) {
32
            if (data.contains(",")) {
33
                for (String entry : data.split(",")) {
34
                    parseEntry(entry);
35
                }
36
            } else {
37
                parseEntry(data);
38
            }
39
        }
40
    }
41

    
42
    private void parseEntry(String entry) {
43
        if (entry.startsWith("Diagram:") && entry.contains(":node")) {
44
            MigrationDiagramNode ng = new MigrationDiagramNode(entry);
45
            if(!this.diagrams.contains(ng.getDiagram())){
46
                this.diagrams.add(ng.getDiagram());
47
            }
48
            this.diagramNodes.add(ng);
49
        } else if (entry.startsWith("Diagram:") && entry.contains(":link")) {
50
            MigrationDiagramLink lk = new MigrationDiagramLink(entry);
51
            if(!this.diagrams.contains(lk.getDiagram())){
52
                this.diagrams.add(lk.getDiagram());
53
            }
54
            this.diagramLinks.add(lk);
55
         
56
        } else if (entry.startsWith("InformationFlow")) {
57
            this.informationsflows.add(new MigrationInformationFlow(entry));
58
        }
59
    }
60

    
61
    public List<MigrationDiagramNode> getDiagramNodes() {
62
        return diagramNodes;
63
    }
64

    
65
    public List<MigrationDiagramLink> getDiagramLinks() {
66
        return diagramLinks;
67
    }
68

    
69
    public List<MigrationInformationFlow> getInformationsflows() {
70
        return informationsflows;
71
    }
72

    
73
    public Set<AbstractDiagram> getDiagrams() {
74
        return diagrams;
75
    }
76

    
77
    public class MigrationInformationFlow {
78
        private boolean source;
79

    
80
        private InformationFlow flow;
81

    
82
        public MigrationInformationFlow(String data) {
83
            if(data.contains("InformationTarge")){
84
                this.source = true;
85
            }else if(data.contains("InformationSource")){
86
                this.source = false; 
87
            }
88
            
89
            String id = data.substring(data.indexOf(":") + 1,data.indexOf("]"));
90
            flow = TogafArchitectModule.getInstance().getModuleContext().getModelingSession().findElementById(InformationFlow.class, id);
91
        }
92

    
93
        public InformationFlow getFlow() {
94
            return flow;
95
        }
96

    
97
        public boolean isSource() {
98
            return source;
99
        }
100

    
101
    }
102

    
103
}