Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The base Server class is refactored to use a Spring application context to resolve Module references.  Bean definitions for Modules are built up programmatically based on the existing, reflection-based Module instantiation and parsed fcfg data.  The Server is auto-wired into the modules.  Module configurations and Datastore configurations are loaded as beans as well, with the former named as role + "Configuration", and the latter named with the datastore id.  This allows existing code that does not need access to Spring beans to run unchanged.

Code Block

    protected static GenericBeanDefinition createModuleBeanDefinition(String className, Object params, String role){

       GenericBeanDefinition result = new GenericBeanDefinition();
       result.setScope(BeanDefinition.SCOPE_SINGLETON);
       result.setBeanClassName(className);
       result.setAttribute("id", role);
       result.setAttribute("name", role);
       result.setAttribute("init-method", "initModule");
       result.setAttribute("destroy-method", "shutdownModule");
       result.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);


       ConstructorArgumentValues cArgs = new ConstructorArgumentValues();
       cArgs.addIndexedArgumentValue(0, params,MODULE_CONSTRUCTOR_PARAM1_CLASS);
       // the server constructor arg (index 1) is autowired with the Server bean in context
       cArgs.addIndexedArgumentValue(2, role,MODULE_CONSTRUCTOR_PARAM3_CLASS);
       result.setConstructorArgumentValues(cArgs);
       return result;
   }

 

    protected static GenericBeanDefinition createModuleConfigurationBeanDefinition(String role){
       GenericBeanDefinition result = new GenericBeanDefinition();
       result.setScope(BeanDefinition.SCOPE_SINGLETON);
       result.setBeanClassName(ModuleConfiguration.class.getName());
       String name = role+"Configuration";
       result.setAttribute("id", name);
       result.setAttribute("name", name);
       result.setFactoryBeanName(ServerConfiguration.class.getName());
       result.setFactoryMethodName("getModuleConfiguration");

       ConstructorArgumentValues cArgs = new ConstructorArgumentValues();
       cArgs.addGenericArgumentValue(role);
       result.setConstructorArgumentValues(cArgs);
       return result;
   }

 

    protected static GenericBeanDefinition createDatastoreConfigurationBeanDefinition(String id){

       GenericBeanDefinition result = new GenericBeanDefinition();
       result.setScope(BeanDefinition.SCOPE_SINGLETON);
       result.setBeanClassName(DatastoreConfiguration.class.getName());
       result.setAttribute("id", id);
       result.setAttribute("name", id);
       result.setFactoryBeanName(ServerConfiguration.class.getName());
       result.setFactoryMethodName("getDatastoreConfiguration");

       ConstructorArgumentValues cArgs = new ConstructorArgumentValues();
       cArgs.addGenericArgumentValue(id);


       result.setConstructorArgumentValues(cArgs);
       return result;

    }



...

Code Block
    @Resource(name = "org.trippi.TriplestoreConnector")
    public void setTriplestoreConnector(TriplestoreConnector conn){
        m_conn = conn;
    }
 
    @Resource(name = configName)
    public void setModuleConfiguration(ModuleConfiguration riConfig) {
        m_riConfig = riConfig;
    }

... Or they can be Spring-aware, and get Beans directly:

Code Block

     private static Rebuilder getRebuilder() throws Exception {private static Rebuilder getRebuilder() throws Exception {
        Server server = getServer();
        String [] rebuilders = server.getBeanNamesForType(Rebuilder.class);
        String[] labels = new String[rebuilders.length + 1];
        int i = 0;
        for (i = 0; i < rebuilders.length; i++) {
            Rebuilder r =
                server.getBean(rebuilders[i],Rebuilder.class);
            labels[i] = r.getAction();
        }
        labels[i] = "Exit";
        int choiceNum = getChoice("What do you want to do?", labels);
        if (choiceNum == i) {
            return null;
        } else {
            return server.getBean(rebuilders[choiceNum],Rebuilder.class);
        }
    }
        Server server = getServer();