-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathKerMLTraversalUtil.java
More file actions
119 lines (108 loc) · 3.75 KB
/
Copy pathKerMLTraversalUtil.java
File metadata and controls
119 lines (108 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*****************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2019 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Eclipse Public License as published by
* the Eclipse Foundation, version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Eclipse Public License for more details.
*
* You should have received a copy of theEclipse Public License
* along with this program. If not, see <https://www.eclipse.org/legal/epl-2.0/>.
*
* @license EPL-2.0 <http://spdx.org/licenses/EPL-2.0>
*
* Contributors:
* Ed Seidewitz
*
*****************************************************************************/
package org.omg.kerml.xtext.util;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.omg.kerml.xtext.KerMLStandaloneSetup;
import org.omg.sysml.io.SysMLUtil;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.util.traversal.Traversal;
import org.omg.sysml.util.traversal.facade.ElementProcessingFacade;
import org.omg.sysml.util.traversal.facade.impl.DefaultElementProcessingFacadeImpl;
/**
* This is a utility for traversing a KerML model graph and processing each Element that is
* visited. The processing to be carried out is determined by a given element-processing facade.
* By default, the processing consists of simply printing out a string representation of each
* Element that is visited.
*
* @author Ed Seidewitz
*
*/
public class KerMLTraversalUtil extends SysMLUtil {
/**
* The traversal object used to manage the traversal of the model graph.
*/
protected Traversal traversal;
public KerMLTraversalUtil() {
super();
KerMLStandaloneSetup.doSetup();
this.addExtension(".kerml");
}
/**
* Get the traversal object for this model traversal.
*
* @return the traversal object.
*/
public Traversal getTraversal() {
return this.traversal;
}
/**
* Initialize the traversal using the given element-processing facade.
*
* @param processingFacade the facade for processing Elements and Relationships
* @return the initialized traversal object
*/
protected Traversal initialize(ElementProcessingFacade processingFacade) {
this.traversal = new Traversal(processingFacade);
return this.traversal;
}
/**
* Visit each of the top-level model Elements in each of the current input Resources.
* Traversal must be initialized before processing.
*/
public void process() {
for (Resource resource: this.getInputResources()) {
for (EObject object : resource.getContents()) {
if (object instanceof Element) {
this.traversal.visit((Element) object);
}
}
}
}
/**
* Run the traversal for the given main program arguments.
*
* @param args the array of main program arguments
*/
public void run(String[] args) {
try {
this.initialize(new DefaultElementProcessingFacadeImpl());
this.read(args);
println("Processing...");
this.process();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* The main program reads the KerML resources as given by its arguments and then processes all the input
* resources. Elements from library resources are only traversed if they are referenced from an input
* or are directly or indirectly related to another Element so referenced.
*
* @param args the first argument is a path for reading input resources, while other arguments
* are paths for reading library resources
*/
public static void main(String[] args) {
new KerMLTraversalUtil().run(args);
}
}