1 Reply Latest reply on Oct 29, 2007 11:39 AM by Ales Justin

    Demand / Supply string transformation

    Ales Justin Master

      Talking yesterday at Zurich JUG, describing our IoC, when mentioning Demand/Supply, Bela got an idea of extending that notion with a regexp.

      Thinking about it, we could have a generic 'transfromer' attribute on the demand/supply element.

      e.g.

      <demand transformer="org.jboss.ioc.transformer.RegExp">^[A-Z0-9._%+-]+@jboss\.((org)|(com))$</demand>
      
      <supply>mc@jboss.org</supply>
      
      <demand transformer="org.jboss.ioc.transformer.IntLimit">(0,255]</demand>
      
      <supply transformer="org.jboss.util.propertyeditor.IntegerEditor">128</supply>
      


      Where a demand transformer would create Matcheable, supply transformer would simple be a PropertyEditor.

      e.g.
      public interface Matcheable
      {
       boolean match(Object other);
      }
      
      for(Map.Entry entry : suppliers.keySet())
      {
       if (name instance of Matcheable)
       {
       Matcheable matcheable = (Matcheable)name;
       if (matcheable.match(entry.getKey()))
       List<KernelControllerContext> list = entry.getValue();
       if (list != null && list.isEmpty() == false)
       return list.get(0);
       }
      
       ...
      }
      





        • 1. Re: Demand / Supply string transformation
          Ales Justin Master

          Done - already commited in the trunk.

          This test case shows what you can do:

           public void testMatching() throws Throwable
           {
           setBeanMetaDatas();
          
           ControllerContext regexpDemand = assertInstall(0, "regexpDemander", getState());
           assertInstall(1, "regexpSupplier");
           assertEquals(ControllerState.INSTALLED, regexpDemand.getState());
          
           ControllerContext limitDemand = assertInstall(2, "intervalDemander", getState());
           assertInstall(3, "intervalSupplier");
           assertEquals(ControllerState.INSTALLED, limitDemand.getState());
          
           ControllerContext customDemand = assertInstall(4, "customDemander", getState());
           assertInstall(5, "customSupplier");
           assertEquals(ControllerState.INSTALLED, customDemand.getState());
           }
          
           protected ControllerState getState()
           {
           return ControllerState.PRE_INSTALL;
           }
          
           protected void setBeanMetaDatas() throws Throwable
           {
           BeanMetaDataBuilder b0 = BeanMetaDataBuilderFactory.createBuilder("regexpDemander", Object.class.getName());
           b0.addDemand("^[a-zA-Z0-9._%+-]+@acme\\.((org)|(com))$", null, "regexp");
           BeanMetaDataBuilder b1 = BeanMetaDataBuilderFactory.createBuilder("regexpSupplier", Object.class.getName());
           b1.addSupply("aj@acme.org");
          
           BeanMetaDataBuilder b2 = BeanMetaDataBuilderFactory.createBuilder("intervalDemander", Object.class.getName());
           b2.addDemand("(1,10]", null, "interval");
           BeanMetaDataBuilder b3 = BeanMetaDataBuilderFactory.createBuilder("intervalSupplier", Object.class.getName());
           b3.addSupply("5", "java.lang.Integer");
          
           BeanMetaDataBuilder b4 = BeanMetaDataBuilderFactory.createBuilder("customDemander", Object.class.getName());
           b4.addDemand("fragment", null, CustomMatcherTransfomer.class.getName());
           BeanMetaDataBuilder b5 = BeanMetaDataBuilderFactory.createBuilder("customSupplier", Object.class.getName());
           b5.addSupply("i supply fragment word");
          
           setBeanMetaDatas(new BeanMetaData[]
           {
           b0.getBeanMetaData(),
           b1.getBeanMetaData(),
           b2.getBeanMetaData(),
           b3.getBeanMetaData(),
           b4.getBeanMetaData(),
           b5.getBeanMetaData(),
           }
           );
           }