Hi,

The NodeFactory SPI is the entry point to Tuscany's runtime. It's backed by an ExtensionPointRegistry which manages extension points, which in turn collect extensions.

I added the support to configure a NodeFactory with a map of attributes by the service types. The following test case demonstrates such usage:

Map<String, Map<String, String>> attrs = new HashMap<String, Map<String, String>>();
       Map<String, String> map = new HashMap<String, String>();
       map.put("enabled", "false");
       attrs.put(ValidationSchemaExtensionPoint.class.getName(), map);

       Map<String, String> map2 = new HashMap<String, String>();
       map2.put("urn:MyDomain", "multicast://200.0.0.100:50000/MyDomain");
attrs.put(DomainRegistryFactoryExtensionPoint.class.getName(), map2);

NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance(attrs);
       
Assert.assertFalse(factory.getExtensionPoints().getExtensionPoint(ValidationSchemaExtensionPoint.class)
           .isEnabled());

DomainRegistryFactoryExtensionPoint domainRegistryFactoryExtensionPoint =
           
factory.getExtensionPoints().getExtensionPoint(DomainRegistryFactoryExtensionPoint.class);
Map<String, String> mapping = domainRegistryFactoryExtensionPoint.getDomainRegistryMapping();
       Assert.assertEquals(1, mapping.size());
Assert.assertEquals("multicast://200.0.0.100:50000/MyDomain", mapping.get("urn:MyDomain"));

The map of attributes for a given extension point/extension override the settings in META-INF/services/<SPI> file. To enable an extension point/extension implementation class with such configurations, we can simply change the constructor to take the Map<String, String>, for example:

public DefaultValidationSchemaExtensionPoint(ExtensionPointRegistry registry, Map<String, String> attributes) {
       super();
       this.registry = registry;
       if (attributes != null) {
           String attr = attributes.get("enabled");
           if (attr != null) {
               enabled = Boolean.parseBoolean(attr);
           }
       }
   }

Comments?

Thanks,
Raymond
---
Raymond Feng
Apache Tuscany PMC Member: http://tuscany.apache.org
Co-author of Tuscany In Action (A book on Tuscany SCA): http://tuscanyinaction.com/
www.enjoyjava.com
http://twitter.com/raymondfeng


Reply via email to