Advertisement
Guest User

fix_invoke_special_targets

a guest
Feb 11th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.63 KB | None | 0 0
  1. Index: src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java
  2. ===================================================================
  3. --- src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java  (Revision 1658973)
  4. +++ src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java  (Arbeitskopie)
  5. @@ -431,6 +431,8 @@
  6.          }
  7.          invokeIds.put(invoke, invokeId);
  8.          invokers.put(invokeId, invoker);
  9. +        ioProcessors.put(String.format(CHILD_IOPROCESSOR_PATTERN, invokeId), invoker.getChildIOProcessor());
  10. +        initializeIOProcessors();
  11.      }
  12.  
  13.      /**
  14. @@ -439,6 +441,8 @@
  15.       */
  16.      public void removeInvoker(final Invoke invoke) {
  17.          invokers.remove(invokeIds.remove(invoke));
  18. +        ioProcessors.remove(String.format(CHILD_IOPROCESSOR_PATTERN, invoke.getId()));
  19. +        initializeIOProcessors();
  20.      }
  21.  
  22.      /**
  23. @@ -468,6 +472,18 @@
  24.      }
  25.  
  26.      /**
  27. +     * Allow registering of the parent IO processor if we are being executed
  28. +     * from an invoke instance.
  29. +     *
  30. +     * @param parentIOProcessor The IOProcessor of the parent instance.
  31. +     */
  32. +    public void registerParentIOProcessor(SCXMLIOProcessor parentIOProcessor) {
  33. +        appLog.info("Registering " + SCXML_PARENT_EVENT_PROCESSOR + ": " + parentIOProcessor);
  34. +        ioProcessors.put(SCXML_PARENT_EVENT_PROCESSOR, parentIOProcessor);
  35. +        initializeIOProcessors();
  36. +    }
  37. +
  38. +    /**
  39.       * Add an event to the internal event queue
  40.       * @param event The event
  41.       */
  42. Index: src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java
  43. ===================================================================
  44. --- src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java  (Revision 1658973)
  45. +++ src/main/java/org/apache/commons/scxml2/SCXMLExecutor.java  (Arbeitskopie)
  46. @@ -323,6 +323,16 @@
  47.      public void unregisterInvokerClass(final String type) {
  48.          exctx.unregisterInvokerClass(type);
  49.      }
  50. +    
  51. +    /**
  52. +     * Register the parent IO Processor, done by the Invoker constructing this instance
  53. +     * to allow communication to the special target #_parent
  54. +     *
  55. +     * @param parentIOProcessor The IOProcessor of the parent instance.
  56. +     */
  57. +    public void registerParentIOProcessor(SCXMLIOProcessor parentIOProcessor) {
  58. +        exctx.registerParentIOProcessor(parentIOProcessor);
  59. +    }
  60.  
  61.      /**
  62.       * Detach the current SCInstance to allow external serialization.
  63. Index: src/main/java/org/apache/commons/scxml2/SCXMLIOProcessor.java
  64. ===================================================================
  65. --- src/main/java/org/apache/commons/scxml2/SCXMLIOProcessor.java   (Revision 1658973)
  66. +++ src/main/java/org/apache/commons/scxml2/SCXMLIOProcessor.java   (Arbeitskopie)
  67. @@ -31,6 +31,16 @@
  68.       * Default SCXML I/O Event Processor alias
  69.       */
  70.      String SCXML_EVENT_PROCESSOR = "scxml";
  71. +    
  72. +    /**
  73. +     * Default SCXML I/O Event Processor alias
  74. +     */
  75. +    String SCXML_PARENT_EVENT_PROCESSOR = "#_parent";
  76. +    
  77. +    /**
  78. +     * Pattern to construct the IOProcessor key for child instances
  79. +     */
  80. +    String CHILD_IOPROCESSOR_PATTERN = "#_%s";
  81.  
  82.      /**
  83.       * The name of the internal Event Processor
  84. Index: src/main/java/org/apache/commons/scxml2/env/SimpleDispatcher.java
  85. ===================================================================
  86. --- src/main/java/org/apache/commons/scxml2/env/SimpleDispatcher.java   (Revision 1658973)
  87. +++ src/main/java/org/apache/commons/scxml2/env/SimpleDispatcher.java   (Arbeitskopie)
  88. @@ -185,13 +185,15 @@
  89.              SCXMLIOProcessor ioProcessor;
  90.  
  91.              boolean internal = false;
  92. +            
  93. +            log.info("Available ioProcessors: " + ioProcessors);
  94.  
  95.              if (target == null) {
  96.                  ioProcessor = ioProcessors.get(SCXMLIOProcessor.SCXML_EVENT_PROCESSOR);
  97.              }
  98. -            else if (SCXMLIOProcessor.INTERNAL_EVENT_PROCESSOR.equals(target)) {
  99. -                ioProcessor = ioProcessors.get(SCXMLIOProcessor.INTERNAL_EVENT_PROCESSOR);
  100. -                internal = true;
  101. +            else if (ioProcessors.containsKey(target)) {
  102. +                ioProcessor = ioProcessors.get(target);
  103. +                internal = SCXMLIOProcessor.INTERNAL_EVENT_PROCESSOR.equals(target);
  104.              }
  105.              else {
  106.                  // We know of no other target
  107. Index: src/main/java/org/apache/commons/scxml2/invoke/Invoker.java
  108. ===================================================================
  109. --- src/main/java/org/apache/commons/scxml2/invoke/Invoker.java (Revision 1658973)
  110. +++ src/main/java/org/apache/commons/scxml2/invoke/Invoker.java (Arbeitskopie)
  111. @@ -89,6 +89,14 @@
  112.       * @param parentIOProcessor The I/O Processor of the parent state machine.
  113.       */
  114.      void setParentIOProcessor(SCXMLIOProcessor parentIOProcessor);
  115. +    
  116. +    /**
  117. +     * Get the child IO Processor to register for communication with
  118. +     * the parent session.
  119. +     *
  120. +     * @return Child IO Processor
  121. +     */
  122. +    SCXMLIOProcessor getChildIOProcessor();
  123.  
  124.      /**
  125.       * Set the Evaluator to be used by the child state machine (to ensure/enforce a compatible data model)
  126. Index: src/main/java/org/apache/commons/scxml2/invoke/SimpleSCXMLInvoker.java
  127. ===================================================================
  128. --- src/main/java/org/apache/commons/scxml2/invoke/SimpleSCXMLInvoker.java  (Revision 1658973)
  129. +++ src/main/java/org/apache/commons/scxml2/invoke/SimpleSCXMLInvoker.java  (Arbeitskopie)
  130. @@ -113,6 +113,7 @@
  131.          }
  132.          executor.addListener(scxml, new SimpleSCXMLListener());
  133.          executor.registerInvokerClass("scxml", this.getClass());
  134. +        executor.registerParentIOProcessor(parentIOProcessor);
  135.          try {
  136.              executor.go();
  137.          } catch (ModelException me) {
  138. @@ -149,5 +150,9 @@
  139.          executor.addEvent(new TriggerEvent("cancel.invoke."+parentStateId, TriggerEvent.CANCEL_EVENT));
  140.      }
  141.  
  142. -}
  143. -
  144. +    @Override
  145. +    public SCXMLIOProcessor getChildIOProcessor() {
  146. +        return executor;
  147. +    }
  148. +    
  149. +}
  150. \ No newline at end of file
  151. Index: src/test/java/org/apache/commons/scxml2/invoke/InvokeParamNameTest.java
  152. ===================================================================
  153. --- src/test/java/org/apache/commons/scxml2/invoke/InvokeParamNameTest.java (Revision 1658973)
  154. +++ src/test/java/org/apache/commons/scxml2/invoke/InvokeParamNameTest.java (Arbeitskopie)
  155. @@ -121,6 +121,11 @@
  156.          public void setParentIOProcessor(SCXMLIOProcessor parentIOProcessor) {
  157.              // Not needed    
  158.          }
  159. +
  160. +        @Override
  161. +        public SCXMLIOProcessor getChildIOProcessor() {
  162. +            return null;
  163. +        }
  164.      }
  165.  
  166.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement