/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telefonica.tcloud.moncollector;

import com.telefonica.tcloud.collectorinterfaces.CollectdName2FQNMap;
import com.telefonica.tcloud.collectorinterfaces.CollectdName2FQNMapFactory;
import com.telefonica.tcloud.collectorinterfaces.MonPersistence;
import com.telefonica.tcloud.collectorinterfaces.MonPersistenceFactory;
import com.telefonica.tcloud.collectorinterfaces.MonPublisher;
import com.telefonica.tcloud.collectorinterfaces.MonPublisherFactory;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Properties;

/**
 *
 * @author jomar
 */
public class DInjector {
       
    public void inject(String fileName,Collector collector) throws IOException {
        Properties properties=new Properties();
        properties.load(new FileReader(fileName));
        inject(properties,collector);
    }
    public void inject(Properties properties,Collector collector) throws
            IOException  {
        LinkedHashMap<String,String[]> configuration=new LinkedHashMap();
        MonPersistence monPersistence=null;
                
        for(String key : properties.stringPropertyNames()) {
            String values[]=new String[1];
            values[0]=properties.getProperty(key);
            configuration.put(key, values);
        }
        
        String measuresFilterName=properties.getProperty("measuresfilter.path");
        String hostFilterName=properties.getProperty("hostfilter.path");
        String publisher=properties.getProperty("publisher.class");
        String persistence=properties.getProperty("persistence.class");
        String conversor=properties.getProperty("conversor2fqn.class");
        String measuresTypesDir=properties.getProperty("measuretypes.path");
        
        
        collector.setHostFilter(hostFilterName!=null?new HostFilter(hostFilterName)
                :null);
        collector.setMeasuresFilter(measuresFilterName!=null?
                new MeasuresFilter(measuresFilterName):null);
        
        if (publisher!=null) {
            MonPublisher monPublisher=MonPublisherFactory.getPublisher(
                    publisher,configuration);
            collector.setMonPublisher(monPublisher);
                    
        } else collector.setMonPublisher(null);
        if (persistence!=null) {
            collector.setMonPersistence(monPersistence=
                MonPersistenceFactory.getPersistence(persistence, configuration)
                    );
        } else collector.setMonPersistence(null);
        if (conversor!=null) {
            //Class.forName("").getConstructor(String.class).newInstance("");
            CollectdName2FQNMap map=CollectdName2FQNMapFactory.getConversor(
                    conversor, configuration);
            map.setMonPersistence(monPersistence);
            collector.setConversor2FQN(map);
                    
        } else collector.setConversor2FQN(null);
        collector.setMeasuresTypeTable(measuresTypesDir!=null
                ?new MeasureTypeTable(measuresTypesDir)
                :new MeasureTypeTable());
        
        
    }
}

@@ -610,16 +610,76 @@
 eption;%0A
+import java.net.MalformedURLException;%0Aimport java.net.URL;%0A
 import j
@@ -760,16 +760,18 @@
 mar%0A */%0A
+%0A%0A
 public c
@@ -787,24 +787,456 @@
 ector %7B%0A    
+%0A    public static final String default_modules_path=%22/opt/monitoring/shared/modules/%22;%0A    private URL%5B%5D jarList2URLs(String baseDir,String jarList) throws MalformedURLException %7B%0A      String jars%5B%5D=jarList.split(%22,%22);%0A      URL urls%5B%5D=new URL%5Bjars.length%5D;%0A      String baseUrl=%22file://%22+baseDir+'/';%0A      int cont=0;%0A      for (String jar: jars) %7B%0A          urls%5Bcont++%5D=new URL(baseUrl+jar);%0A      %7D%0A      return urls;%0A    %7D%0A 
    %0A    publ
@@ -1896,32 +1896,95 @@
      %7D%0A        %0A
+        String modules=properties.getProperty(%22modules.path%22);%0A
         String m
@@ -2411,32 +2411,89 @@
 ath%22);%0A        %0A
+        if (modules==null) modules=default_modules_path;%0A
         %0A       
@@ -2749,32 +2749,183 @@
 lisher!=null) %7B%0A
+            String publisherJars=properties.getProperty(%22publisher.jars%22);%0A            URL jarURLs%5B%5D=jarList2URLs(modules,publisherJars);%0A            %0A
             MonP
@@ -3010,16 +3010,24 @@
 blisher,
+jarURLs,
 configur
@@ -3181,32 +3181,176 @@
 stence!=null) %7B%0A
+            String persistenceJars=properties.getProperty(%22persistence.jars%22);%0A            URL jarURLs%5B%5D=jarList2URLs(modules,persistenceJars);%0A
             coll
@@ -3454,16 +3454,45 @@
 istence,
+ jarURLs,%0A                   
  configu
@@ -3677,24 +3677,166 @@
 stance(%22%22);%0A
+            String conversorJars=properties.getProperty(%22conversor2fqn.jars%22);%0A            URL jarURLs%5B%5D=jarList2URLs(modules,conversorJars);%0A
             

use library path to load classes