TestModels.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * Copyright (c) 2012 committers of YAKINDU and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * committers of YAKINDU - initial API and implementation
  10. */
  11. package util;
  12. import java.io.IOException;
  13. import org.eclipse.emf.common.util.URI;
  14. import org.eclipse.emf.ecore.resource.Resource;
  15. import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
  16. import org.eclipse.emf.ecore.util.EcoreUtil;
  17. import org.yakindu.sct.model.sexec.ExecutionFlow;
  18. import org.yakindu.sct.model.sexec.transformation.ModelSequencer;
  19. import org.yakindu.sct.model.sgraph.SGraphPackage;
  20. import org.yakindu.sct.model.sgraph.Statechart;
  21. import com.google.inject.Inject;
  22. /**
  23. * Provides access to the testmodels.
  24. *
  25. * @author andreas muelder - Initial contribution and API
  26. *
  27. */
  28. public class TestModels {
  29. private static final String TESTMODEL_DIR = "org.yakindu.sct.test.models/testmodels/";
  30. public static final String GUARD = "Guard.sct";
  31. public static final String SIMPLE_HIERACHY = "SimpleHierachy.sct";
  32. public static final String DEEP_HISTORY = "DeepHistory.sct";
  33. public static final String STATE_ACTIVE = "StateIsActive.sct";
  34. public static final String VALUED_EVENTS = "ValuedEvents.sct";
  35. public static final String FEATURE_CALLS = "FeatureCalls.sct";
  36. public static final String STATECHART_LOCAL_REACTIONS = "StatechartLocalReactions.sct";
  37. @Inject
  38. private ModelSequencer sequencer;
  39. /**
  40. * <img src="../../images/Guard.png" /> <br />
  41. *
  42. * @return the {@link ExecutionFlow}
  43. * @throws IOException
  44. */
  45. public ExecutionFlow createGuardModel() throws IOException {
  46. return loadExecutionFlowFromResource(GUARD);
  47. }
  48. /**
  49. * <img src="../../images/SimpleHierachy.png" /> <br />
  50. *
  51. * @return the {@link ExecutionFlow}
  52. * @throws IOException
  53. */
  54. public ExecutionFlow createSimpleHierachyModel() throws IOException {
  55. return loadExecutionFlowFromResource(SIMPLE_HIERACHY);
  56. }
  57. /**
  58. * <img src="../../images/DeepHistory.png" /> <br />
  59. *
  60. * @return the {@link ExecutionFlow}
  61. * @throws IOException
  62. */
  63. public ExecutionFlow createDeepHistoryModel() throws IOException {
  64. return loadExecutionFlowFromResource(DEEP_HISTORY);
  65. }
  66. /**
  67. * <img src="../../images/StateIsActive.png" /> <br />
  68. *
  69. * @return the {@link ExecutionFlow}
  70. * @throws IOException
  71. */
  72. public ExecutionFlow createStateIsActiveModel() throws IOException {
  73. return loadExecutionFlowFromResource(STATE_ACTIVE);
  74. }
  75. /**
  76. * <img src="../../images/ValuedEvents.png" /> <br />
  77. *
  78. * @return the {@link ExecutionFlow}
  79. * @throws IOException
  80. */
  81. public ExecutionFlow createValuedEventsModel() throws IOException {
  82. return loadExecutionFlowFromResource(VALUED_EVENTS);
  83. }
  84. /**
  85. * <img src="../../images/FeatureCalls.png" /> <br />
  86. *
  87. * @return the {@link ExecutionFlow}
  88. * @throws IOException
  89. */
  90. public ExecutionFlow createFeatureCallModel() throws IOException {
  91. return loadExecutionFlowFromResource(FEATURE_CALLS);
  92. }
  93. /**
  94. * <img src="../../images/StatechartLocalReactions.png" /> <br />
  95. *
  96. * @return the {@link ExecutionFlow}
  97. * @throws IOException
  98. */
  99. public ExecutionFlow createStatechartLocalReactionsModel()
  100. throws IOException {
  101. return loadExecutionFlowFromResource(STATECHART_LOCAL_REACTIONS);
  102. }
  103. /**
  104. * Helper method - loads a testmodel from the Testmodel directory
  105. *
  106. * @param fileName
  107. * the filename of the testmodel
  108. * @return the {@link ExecutionFlow}
  109. * @throws IOException
  110. */
  111. public ExecutionFlow loadExecutionFlowFromResource(String fileName) throws IOException {
  112. Statechart statechart = loadStatechartFromResource(fileName);
  113. final ExecutionFlow flow = sequencer.transform(statechart);
  114. return flow;
  115. }
  116. public Statechart loadStatechartFromResource(String fileName) {
  117. URI uri = URI.createPlatformPluginURI(TESTMODEL_DIR + fileName, true);
  118. ResourceSetImpl impl = new ResourceSetImpl();
  119. Resource resource = impl.getResource(uri, true);
  120. Statechart statechart = (Statechart) EcoreUtil.getObjectByType(
  121. resource.getContents(), SGraphPackage.Literals.STATECHART);
  122. return statechart;
  123. }
  124. }