use of org.softlang.metalib.emf.fsml.fsml.FSM in project metalib by softlang.
the class FSMStateImpl method isReachable.
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public boolean isReachable(DiagnosticChain diagnostics, Map<Object, Object> context) {
FSM fsm = (FSM) eContainer();
Set<FSMState> reachable = new HashSet<>();
Stack<FSMState> currents = new Stack<FSMState>();
currents.addAll(fsm.getStates().stream().filter(x -> x.isInitial()).collect(Collectors.toSet()));
while (!currents.isEmpty()) {
FSMState current = currents.pop();
if (current == this)
return true;
if (reachable.contains(current))
continue;
reachable.add(current);
for (FSMTransition transition : current.getTransitions()) if (transition.getTarget() != null)
currents.push(transition.getTarget());
}
if (diagnostics != null) {
diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, FsmlValidator.DIAGNOSTIC_SOURCE, FsmlValidator.FSM_STATE__IS_REACHABLE, EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "isReachable", EObjectValidator.getObjectLabel(this, context) }), new Object[] { this }));
}
return false;
}
use of org.softlang.metalib.emf.fsml.fsml.FSM in project metalib by softlang.
the class StandaloneFSMLScenario method main.
public static void main(String[] args) {
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("fsml", new XMIResourceFactoryImpl());
URI uri = URI.createFileURI("path");
Resource resource = rs.createResource(uri);
FSM fsm = (FSM) resource.getContents().get(0);
}
use of org.softlang.metalib.emf.fsml.fsml.FSM in project metalib by softlang.
the class FsmlExample method main.
/**
* <!-- begin-user-doc -->
* Load all the argument file paths or URIs as instances of the model.
* <!-- end-user-doc -->
* @param args the file paths or URIs.
* @generated
*/
public static void main(String[] args) {
// Create a resource set to hold the resources.
//
ResourceSet resourceSet = new ResourceSetImpl();
// Register the appropriate resource factory to handle all file extensions.
//
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put(FsmlPackage.eNS_URI, FsmlPackage.eINSTANCE);
//
if (args.length == 0) {
System.out.println("Enter a list of file paths or URIs that have content like this:");
try {
Resource resource = resourceSet.createResource(URI.createURI("http:///My.fsml"));
FSM root = FsmlFactory.eINSTANCE.createFSM();
resource.getContents().add(root);
resource.save(System.out, null);
} catch (IOException exception) {
exception.printStackTrace();
}
} else {
//
for (int i = 0; i < args.length; ++i) {
// Construct the URI for the instance file.
// The argument is treated as a file path only if it denotes an existing file.
// Otherwise, it's directly treated as a URL.
//
File file = new File(args[i]);
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
try {
// Demand load resource for this file.
//
Resource resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);
//
for (EObject eObject : resource.getContents()) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
if (diagnostic.getSeverity() != Diagnostic.OK) {
printDiagnostic(diagnostic, "");
}
}
} catch (RuntimeException exception) {
System.out.println("Problem loading " + uri);
exception.printStackTrace();
}
}
}
}
use of org.softlang.metalib.emf.fsml.fsml.FSM in project metalib by softlang.
the class StandaloneTurnstile method main.
public static void main(String[] args) {
// Register package as a side-effect.
FsmlPackage.eINSTANCE.eClass();
// The ResourceSet that this standalone application is using.
ResourceSet resourceSet = new ResourceSetImpl();
// Get the registry for ResourceFactories.
Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
// Register the XMIResourceFactory for files with fsml extension.
XMIResourceFactoryImpl xmiResourceFactory = new XMIResourceFactoryImpl();
resourceFactoryRegistry.getExtensionToFactoryMap().put("fsml", xmiResourceFactory);
// Deserialize XMI File.
Resource fsmlResource = resourceSet.getResource(URI.createURI("Turnstile.fsml"), true);
// Read the Turnstile model.
FSM fsmTurnstileEObject = (FSM) fsmlResource.getContents().get(0);
EList<FSMState> fsmTurnstileStateEObjects = fsmTurnstileEObject.getStates();
}
use of org.softlang.metalib.emf.fsml.fsml.FSM in project metalib by softlang.
the class FSMLUtils method load.
public static FSM load(String path) {
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(URI.createURI(path), true);
return (FSM) resource.getContents().get(0);
}
Aggregations