Uploaded image for project: 'SwitchYard'
  1. SwitchYard
  2. SWITCHYARD-428

Defining resources as classes in @Process and @Rules is clunky

    Details

      Description

      Using the switchyard maven plugin and the BPMSwitchYardScanner, the following BPM component configuration:

      <component name="MyService">
        <implementation.bpm processDefinition="META-INF/MyService.bpmn" processDefinitionType="BPMN2" processId="MyService">
          <taskHandler class="org.switchyard.component.bpm.task.SwitchYardServiceTaskHandler" name="SwitchYard Service"/>
          <resource location="/META-INF/MyServiceRules.drl" type="DRL"/>
        </implementation.bpm>
        <service name="MyService">
          <interface.java interface="org.switchyard.userguide.MyService"/>
        </service>
      </component>
      

      can be auto-generated from this:

      @Process(value=MyService.class, resources={MyServiceRules.class})
      public interface MyServiceProcess extends MyService {
        public static final class MyServiceRules extends SimpleResource {
          public MyServiceRules() {
            super("/META-INF/MyServiceRules.drl", "DRL");
          }
        }
      }
      

      Similarly, using the switchyard maven plugin and the RulesSwitchYardScanner, the following Rules component configuration:

      <component name="MyService">
        <implementation.rules stateful="false">
          <rulesAction name="process" type="EXECUTE_RULES"/>
          <resource location="/org/switchyard/userguide/MyService.drl" type="DRL"/>
        </implementation.rules>
        <service name="MyService">
          <interface.java interface="org.switchyard.userguide.MyService"/>
        </service>
      </component>
      

      can be auto-generated from this:

      @Rules(value=MyService.class, resources={MyServiceDrl.class})
      public interface MyServiceRules extends MyService {
        @ExecuteRules
        public void process(MyData data);
        public static final class MyServiceDrl extends SimpleResource {
          public MyServiceDrl() {
            super("/org/switchyard/userguide/MyService.drl", "DRL");
          }
        }
      }
      

      The problem is that using a CLASSES array (of static classes) to define resources is VERY clunky, and causes the user to write a lot more code than he/she needs to. Instead, the resources array of the Rules annotation should instead just be an array of STRINGS pointing to the location of the resources.

      The original reasoning behind using classes was that there were two different pieces of data to describe a resource: a location and a type. However, as part of this work, if we add a way for the ResourceType class (which already exists and is extensible to user-added types) to deduce the type via the file extension, then just the location would be required.

      With this change, the above BPM code would be reduced to this:

      @Process(value=MyService.class, resources={"/org/switchyard/userguide/MyService.drl"})
      public interface MyServiceProcess extends MyService {}
      

      , and the above Rules code would be reduced to this:

      @Rules(value=MyService.class, resources={"/org/switchyard/userguide/MyService.drl"})
      public interface MyServiceRules extends MyService {
        @ExecuteRules
        public void process(MyData data);
      }
      

      A lot cleaner!

        Gliffy Diagrams

          Activity

          Show
          dward David Ward added a comment - https://github.com/jboss-switchyard/core/pull/291 https://github.com/jboss-switchyard/components/pull/221 https://github.com/jboss-switchyard/quickstarts/pull/71
          Hide
          kcbabo Keith Babo added a comment -

          pushed

          Show
          kcbabo Keith Babo added a comment - pushed

            People

            • Assignee:
              dward David Ward
              Reporter:
              dward David Ward
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development