Changeset 1056 for branches


Ignore:
Timestamp:
2009-02-11 12:59:13 (3 years ago)
Author:
bruno
Message:

Configuration:

  • further conf/runtime -> conf/kauri renaming, removing remaining kauri.xml references.
  • introduce Spring <kauri:conf path="..." [select="..."]/> tag, to allow easy injecting of Conf objects into beans from the spring container. Also allows retrieving a single string value using an expression, though that is pretty much equivalent to using the ConfPlaceholderConfigurer?, but it could be extended in the future to allow returning lists of strings.
Location:
branches/BRANCH_CONFIG
Files:
8 added
13 deleted
8 edited
11 copied
11 moved

Legend:

Unmodified
Added
Removed
  • branches/BRANCH_CONFIG/core/kauri-runtime-tests/src/test/java/org/kauriproject/runtime/test/ConfListeningTest.java

    r1050 r1056  
    4242 
    4343        // Create a config for the configuration manager 
    44         File runtimeConfDir = new File(test1ConfDir, "runtime"); 
    45         writeConf(runtimeConfDir, "configuration.xml", "<conf><reloading enabled='true' delay='1000'/></conf>"); 
     44        File kauriConfDir = new File(test1ConfDir, "kauri"); 
     45        writeConf(kauriConfDir, "configuration.xml", "<conf><reloading enabled='true' delay='1000'/></conf>"); 
    4646 
    4747        // Create a conf for our test module 
  • branches/BRANCH_CONFIG/core/kauri-runtime-tests/src/test/java/org/kauriproject/runtime/test/ConfTest.java

    r1044 r1056  
    66import org.kauriproject.runtime.configuration.ConfManager; 
    77import org.kauriproject.runtime.configuration.ConfManagerImpl; 
     8import org.kauriproject.runtime.test.testmodules.confmod.ConfDependentBean; 
    89import org.kauriproject.conf.Conf; 
     10import org.springframework.context.ApplicationContext; 
    911 
    1012import java.io.File; 
     
    4143 
    4244    public void testConf() { 
    43         Map beans = runtime.getModuleById("confmod").getApplicationContext().getBeansOfType(ConfRegistry.class); 
     45        ApplicationContext appContext = runtime.getModuleById("confmod").getApplicationContext(); 
     46 
     47        Map beans = appContext.getBeansOfType(ConfRegistry.class); 
    4448        ConfRegistry confRegistry = (ConfRegistry)beans.get("conf"); 
    4549 
     
    5458        assertEquals(599, conf.getChild("delay").getValueAsInteger()); 
    5559 
    56         String confTestBean1 = (String)runtime.getModuleById("confmod").getApplicationContext().getBean("confTestBean1"); 
     60        String confTestBean1 = (String)appContext.getBean("confTestBean1"); 
    5761        assertEquals("foobar@hotmail.com", confTestBean1); 
     62 
     63        ConfDependentBean confTestBean2 = (ConfDependentBean)appContext.getBean("confTestBean2"); 
     64        assertNotNull(confTestBean2.getConf()); 
     65        assertEquals("foobar@hotmail.com", confTestBean2.getConf().getChild("email").getValue());         
     66 
     67        String confTestBean3 = (String)appContext.getBean("confTestBean3"); 
     68        assertEquals("foobar@hotmail.com", confTestBean3); 
    5869    } 
    5970 
  • branches/BRANCH_CONFIG/core/kauri-runtime-tests/src/test/modulesrc/org/kauriproject/runtime/test/testmodules/confmod/KAURI-INF/spring/services.xml

    r1044 r1056  
    2323  </bean> 
    2424 
     25  <bean id="confTestBean2" class="org.kauriproject.runtime.test.testmodules.confmod.ConfDependentBean"> 
     26    <constructor-arg> 
     27      <kauri:conf path="test2"/> 
     28    </constructor-arg> 
     29  </bean> 
     30 
     31  <bean id="confTestBean3" class="java.lang.String"> 
     32    <!-- The following is equivalent to the ${path:expr} syntax --> 
     33    <constructor-arg><kauri:conf path="test2" select="email"/></constructor-arg> 
     34  </bean> 
    2535</beans> 
  • branches/BRANCH_CONFIG/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/build/KauriRuntimeNamespaceHandler.java

    r1054 r1056  
    2222import org.springframework.beans.factory.config.ConstructorArgumentValues; 
    2323import org.springframework.beans.factory.support.RootBeanDefinition; 
     24import org.springframework.beans.factory.support.GenericBeanDefinition; 
    2425import org.w3c.dom.Element; 
    2526import org.w3c.dom.Node; 
     
    3031import org.kauriproject.runtime.rapi.KauriModule; 
    3132import org.kauriproject.runtime.rapi.ConfRegistry; 
     33import org.kauriproject.conf.Conf; 
     34import org.apache.commons.jxpath.JXPathContext; 
    3235 
    3336import java.util.Map; 
     
    4750        if (processor != null) { 
    4851            try { 
    49                 processor.process(element, parserContext, springBuildContext); 
     52                return processor.process(element, parserContext, springBuildContext); 
    5053            } catch (Throwable e) { 
    5154                throw new KauriRTException("Error handling " + elementName + " directive.", e); 
     
    6164 
    6265    private static interface ElementProcessor { 
    63         void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws Exception; 
     66        BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws Exception; 
    6467    } 
    6568 
    6669    private static final ElementProcessor MODULE_PROCESSOR = new ElementProcessor() { 
    67         public void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
     70        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
    6871            String contextBeanId = element.getAttribute("restletContext"); 
    6972            if (contextBeanId.length() > 0) { 
     
    124127                parserContext.getRegistry().registerBeanDefinition(confBeanId, def); 
    125128            } 
     129 
     130            return null; 
    126131        } 
    127132    }; 
    128133 
    129134    private static final ElementProcessor IMPORT_RESTSERVICE_PROCESSOR = new ElementProcessor() { 
    130         public void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
     135        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
    131136            String name = element.getAttribute("name"); 
    132137 
     
    136141 
    137142            springBuildContext.importRestservice(name, type); 
     143 
     144            return null; 
    138145        } 
    139146    }; 
    140147 
    141148    private static final ElementProcessor EXPORT_RESTSERVICE_PROCESSOR = new ElementProcessor() { 
    142         public void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
     149        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) { 
    143150            String beanName = element.getAttribute("ref"); 
    144151 
     
    152159 
    153160            springBuildContext.exportRestservice(name, beanName, type); 
     161 
     162            return null; 
    154163        } 
    155164    }; 
    156165 
    157166    private static final ElementProcessor IMPORT_SERVICE_PROCESSOR = new ElementProcessor() { 
    158         public void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws ClassNotFoundException { 
     167        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws ClassNotFoundException { 
    159168            String service = element.getAttribute("service"); 
    160169            Class serviceClass = parserContext.getReaderContext().getBeanClassLoader().loadClass(service); 
     
    184193                } 
    185194            } catch (Throwable t) { 
    186                 throw new KauriRTException("Error assigning Java service dependency " + dependencyName + " of module " + springBuildContext.getModule().getDefinition().getId(), t); 
     195                throw new KauriRTException("Error assigning Java service dependency " + dependencyName + " of module " 
     196                        + springBuildContext.getModule().getDefinition().getId(), t); 
    187197            } 
    188198 
     
    196206            def.setLazyInit(false); 
    197207            parserContext.getRegistry().registerBeanDefinition(id, def); 
     208 
     209            return null; 
    198210        } 
    199211    }; 
    200212 
    201213    private static final ElementProcessor EXPORT_SERVICE_PROCESSOR = new ElementProcessor() { 
    202         public void process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws ClassNotFoundException { 
     214        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) 
     215                throws ClassNotFoundException { 
    203216            String service = element.getAttribute("service"); 
    204217            Class serviceClass = parserContext.getReaderContext().getBeanClassLoader().loadClass(service); 
     
    210223 
    211224            springBuildContext.exportJavaService(name, serviceClass, beanName); 
     225 
     226            return null; 
     227        } 
     228    }; 
     229 
     230    private static final ElementProcessor CONF_PROCESSOR = new ElementProcessor() { 
     231        public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) 
     232                throws Exception { 
     233            String path = element.getAttribute("path"); 
     234            String expr = element.getAttribute("select"); 
     235 
     236            String moduleId = springBuildContext.getModule().getDefinition().getId(); 
     237            Conf conf = springBuildContext.getRuntime().getConfManager().getConfRegistry(moduleId).getConfiguration(path); 
     238 
     239            if (expr.length() > 0) { 
     240                JXPathContext context = JXPathContext.newContext(conf); 
     241                String value; 
     242 
     243                try { 
     244                    value = String.valueOf(context.getValue(expr)); 
     245                } catch (Exception e) { 
     246                    throw new KauriRTException("Element " + element.getTagName() + " of Spring bean config in module " + 
     247                            moduleId + ": error retrieving configuration value using expression \"" + expr + "\"" 
     248                            + " from configuration path \"" + path + "\".", e); 
     249                } 
     250 
     251                GenericBeanDefinition def = new GenericBeanDefinition(); 
     252                def.setBeanClass(ObjectFactoryBean.class); 
     253 
     254                ConstructorArgumentValues args = new ConstructorArgumentValues(); 
     255                args.addIndexedArgumentValue(0, String.class); 
     256                args.addIndexedArgumentValue(1, value); 
     257     
     258                def.setConstructorArgumentValues(args); 
     259                def.setLazyInit(false); 
     260 
     261                return def; 
     262            } else { 
     263                GenericBeanDefinition def = new GenericBeanDefinition(); 
     264                def.setBeanClass(ObjectFactoryBean.class); 
     265 
     266                ConstructorArgumentValues args = new ConstructorArgumentValues(); 
     267                args.addIndexedArgumentValue(0, Conf.class); 
     268                args.addIndexedArgumentValue(1, conf); 
     269 
     270                def.setConstructorArgumentValues(args); 
     271                def.setLazyInit(false); 
     272 
     273                return def; 
     274            } 
    212275        } 
    213276    }; 
     
    222285        ELEMENT_PROCESSORS.put("import-restservice", IMPORT_RESTSERVICE_PROCESSOR); 
    223286        ELEMENT_PROCESSORS.put("module", MODULE_PROCESSOR); 
     287        ELEMENT_PROCESSORS.put("conf", CONF_PROCESSOR); 
    224288    } 
    225289} 
  • branches/BRANCH_CONFIG/core/kauri-runtime/src/main/resources/org/kauriproject/runtime/component/kauriruntime-springext.xsd

    r1033 r1056  
    3636    </xs:complexType> 
    3737  </xs:element> 
     38  <xs:element name="conf"> 
     39    <xs:complexType> 
     40      <xs:attribute name="path" type="xs:string" use="required"/> 
     41      <xs:attribute name="select" type="xs:string" use="optional"/> 
     42    </xs:complexType> 
     43  </xs:element> 
    3844</xs:schema> 
  • branches/BRANCH_CONFIG/samples/kauri-dbresources-sample/src/main/kauri/pages/index.html.xml

    r988 r1056  
    6565            JpaRestlet 
    6666          </b> 
    67           on a path of choice in your kauri.xml file. 
     67          on a path of choice in your wiring.xml file. 
    6868          Note that it got exported from the import mentioned above. 
    69           <br/>(See kauri.xml) 
     69          <br/>(See wiring.xml) 
    7070          <pre><![CDATA[ 
    7171    <artifact id="your.module" groupId="your.groupId" artifactId="your-artifactId"> 
  • branches/BRANCH_CONFIG/tools/kauri-package-plugin/src/main/java/org/kauriproject/tools/plugin/packaging/BasePackageMojo.java

    r1054 r1056  
    2626 
    2727/** 
    28  * Creates a packaged Kauri application from a kauri.xml file. 
     28 * Creates a packaged Kauri application from a wiring.xml file. 
    2929 * 
    3030 * While this is a plugin, it doesn't really work on the current project, 
    31  * but rather gets all its information from the kauri.xml file. 
     31 * but rather gets all its information from the wiring.xml file. 
    3232 * 
    3333 * @requiresDependencyResolution runtime 
    34  * @description Creates a packaged Kauri application from a kauri.xml file. 
     34 * @description Creates a packaged Kauri application from a wiring.xml file. 
    3535 */ 
    3636public abstract class BasePackageMojo extends AbstractPackageMojo { 
     
    6868        // 
    6969        // Create an artifact repository to include in the webapp, containing: 
    70         //   1. the modules listed in the kauri.xml 
     70        //   1. the modules listed in the wiring.xml 
    7171        //   2. for each module, the dependencies listed in its classloader.xml 
    7272        // 
     
    8383 
    8484        // 
    85         // Include the kauri.xml file 
     85        // Include the configuration data 
    8686        // 
    8787        getLog().info("Including the configuration."); 
  • branches/BRANCH_CONFIG/tools/kauri-package-plugin/src/main/java/org/kauriproject/tools/plugin/packaging/BaseWebappMojo.java

    r1054 r1056  
    3030 
    3131/** 
    32  * Creates a Servlet webapp from a kauri.xml file. 
     32 * Creates a Servlet webapp from a wiring.xml file. 
    3333 * 
    3434 * While this is a plugin, it doesn't really work on the current project, 
    35  * but rather gets all its information from the kauri.xml file. 
     35 * but rather gets all its information from the wiring.xml file. 
    3636 * 
    3737 * @requiresDependencyResolution runtime 
    38  * @description Creates a Servlet webapp from a kauri.xml file. 
     38 * @description Creates a Servlet webapp from a wiring.xml file. 
    3939 */ 
    4040public abstract class BaseWebappMojo extends AbstractPackageMojo { 
     
    6868        // 
    6969        // Create an artifact repository to include in the webapp, containing: 
    70         //   1. the modules listed in the kauri.xml 
     70        //   1. the modules listed in the wiring.xml 
    7171        //   2. for each module, the dependencies listed in its classloader.xml 
    7272        // 
     
    8383 
    8484        // 
    85         // Include the kauri.xml file 
     85        // Include the configuration data 
    8686        // 
    8787        getLog().info("Including the configuration."); 
Note: See TracChangeset for help on using the changeset viewer.