3 Replies Latest reply on Dec 22, 2010 6:59 AM by Sergey Zubarev

    [SOLVED] service constructor params

    Sergey Zubarev Newbie

      I created the following service:

       

      package ru.tersys.projects.prodimex.service.impl;
      
      
      import java.io.FileNotFoundException;
      import java.io.FileReader;
      import java.io.IOException;
      import java.util.List;
      
      
      import org.exoplatform.container.xml.InitParams;
      import au.com.bytecode.opencsv.CSVReader;
      
      
      public class CsvReaderServiceImpl{
      
      
          private String CSV_PATH_PATTERN = null;
          
          public CsvReaderServiceImpl(InitParams params) throws Exception
          {
              CSV_PATH_PATTERN = params.getValueParam("tersys.csv.dir.mask").getValue();        
          }
      
      
          public String getFileName(String hour, String date) throws Exception
          {
              return String.format(CSV_PATH_PATTERN, date, hour);
          }
          
          public List<String[]> loadCSV(String filename) throws FileNotFoundException, IOException
          {
             CSVReader reader = new CSVReader(new FileReader(filename), ';', '\'', 1);          
            List<String[]> res = reader.readAll();      
            reader.close();
              
            return res;
          }
      }
      
      
      
      

       

      declared it in conf/portal/configuration.xml

       

       

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <configuration
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
         xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
      
        <component>    
          <type>ru.tersys.projects.prodimex.service.GaugeDataService</type>
        </component>
        
        <component>          
          <type>ru.tersys.projects.prodimex.service.impl.CsvReaderServiceImpl</type>    
          <init-params>
            <values-param>
              <name>tersys.csv.dir.mask</name>        
              <value>123</value>      
            </values-param>
          </init-params>
        </component>
        
      </configuration>
      
      
      
      
      
      

       

      and put jar in lib/ folder in tomcat

       

      But when I try to access this service with following code in webapp:

       

       

      CsvReaderServiceImpl serv =  (CsvReaderServiceImpl)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(CsvReaderServiceImpl.class);
      
      
      

       

      i get exception:

       

       

      Cannot instantiate component key
      =ru.tersys.projects.prodimex.service.impl.CsvReaderServiceImpl type=ru.tersys.pr
      ojects.prodimex.service.impl.CsvReaderServiceImpl found at jar:file:/C:/GateIn/G
      ateIn-3.1.0-GA/lib/tersys-gatein-gaugeDataService-0.0.1-SNAPSHOT.jar!/conf/porta
      l/configuration.xml
      
      
      

       

       

      If i remove service constructor params - all ok.

       

      How make service constructor with parameter(s)?