/tests/net.jgsuess.uml14.tests/src/net/jgsuess/uml14/behavioral_elements/use_cases/tests/Use_casesExample.java

https://gitlab.com/jgsuess/uml-1.4.2 · Java · 125 lines · 64 code · 16 blank · 45 comment · 8 complexity · c31677160ab18b048f882abcf2a48529 MD5 · raw file

  1. /**
  2. * <copyright>
  3. * </copyright>
  4. *
  5. * $Id: Use_casesExample.java,v 1.1 2012/04/23 09:32:43 uqjsuss Exp $
  6. */
  7. package net.jgsuess.uml14.behavioral_elements.use_cases.tests;
  8. import java.io.File;
  9. import java.io.IOException;
  10. import net.jgsuess.uml14.behavioral_elements.use_cases.UseCase;
  11. import net.jgsuess.uml14.behavioral_elements.use_cases.Use_casesFactory;
  12. import net.jgsuess.uml14.behavioral_elements.use_cases.Use_casesPackage;
  13. import org.eclipse.emf.common.util.Diagnostic;
  14. import org.eclipse.emf.common.util.URI;
  15. import org.eclipse.emf.ecore.EObject;
  16. import org.eclipse.emf.ecore.resource.Resource;
  17. import org.eclipse.emf.ecore.resource.ResourceSet;
  18. import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
  19. import org.eclipse.emf.ecore.util.Diagnostician;
  20. import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
  21. /**
  22. * <!-- begin-user-doc -->
  23. * A sample utility for the '<em><b>use_cases</b></em>' package.
  24. * <!-- end-user-doc -->
  25. * @generated
  26. */
  27. public class Use_casesExample {
  28. /**
  29. * <!-- begin-user-doc -->
  30. * Load all the argument file paths or URIs as instances of the model.
  31. * <!-- end-user-doc -->
  32. * @param args the file paths or URIs.
  33. * @generated
  34. */
  35. public static void main(String[] args) {
  36. // Create a resource set to hold the resources.
  37. //
  38. ResourceSet resourceSet = new ResourceSetImpl();
  39. // Register the appropriate resource factory to handle all file extensions.
  40. //
  41. resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
  42. (Resource.Factory.Registry.DEFAULT_EXTENSION,
  43. new XMIResourceFactoryImpl());
  44. // Register the package to ensure it is available during loading.
  45. //
  46. resourceSet.getPackageRegistry().put
  47. (Use_casesPackage.eNS_URI,
  48. Use_casesPackage.eINSTANCE);
  49. // If there are no arguments, emit an appropriate usage message.
  50. //
  51. if (args.length == 0) {
  52. System.out.println("Enter a list of file paths or URIs that have content like this:");
  53. try {
  54. Resource resource = resourceSet.createResource(URI.createURI("http:///My.use_cases"));
  55. UseCase root = Use_casesFactory.eINSTANCE.createUseCase();
  56. resource.getContents().add(root);
  57. resource.save(System.out, null);
  58. }
  59. catch (IOException exception) {
  60. exception.printStackTrace();
  61. }
  62. }
  63. else {
  64. // Iterate over all the arguments.
  65. //
  66. for (int i = 0; i < args.length; ++i) {
  67. // Construct the URI for the instance file.
  68. // The argument is treated as a file path only if it denotes an existing file.
  69. // Otherwise, it's directly treated as a URL.
  70. //
  71. File file = new File(args[i]);
  72. URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()): URI.createURI(args[i]);
  73. try {
  74. // Demand load resource for this file.
  75. //
  76. Resource resource = resourceSet.getResource(uri, true);
  77. System.out.println("Loaded " + uri);
  78. // Validate the contents of the loaded resource.
  79. //
  80. for (EObject eObject : resource.getContents()) {
  81. Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
  82. if (diagnostic.getSeverity() != Diagnostic.OK) {
  83. printDiagnostic(diagnostic, "");
  84. }
  85. }
  86. }
  87. catch (RuntimeException exception) {
  88. System.out.println("Problem loading " + uri);
  89. exception.printStackTrace();
  90. }
  91. }
  92. }
  93. }
  94. /**
  95. * <!-- begin-user-doc -->
  96. * Prints diagnostics with indentation.
  97. * <!-- end-user-doc -->
  98. * @param diagnostic the diagnostic to print.
  99. * @param indent the indentation for printing.
  100. * @generated
  101. */
  102. protected static void printDiagnostic(Diagnostic diagnostic, String indent) {
  103. System.out.print(indent);
  104. System.out.println(diagnostic.getMessage());
  105. for (Diagnostic child : diagnostic.getChildren()) {
  106. printDiagnostic(child, indent + " ");
  107. }
  108. }
  109. } //Use_casesExample