View Javadoc
1   /*
2    * Copyright (C) 2003-2010 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.cs.statistics;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import org.exoplatform.container.xml.InitParams;
22  import org.exoplatform.container.xml.ValuesParam;
23  import org.exoplatform.services.log.ExoLogger;
24  import org.exoplatform.services.log.Log;
25  
26  /**
27   * The configuration of the {@link JCRAPIAspect}
28   * 
29   * Created by The eXo Platform SAS
30   * Author : Nicolas Filotto 
31   *          nicolas.filotto@exoplatform.com
32   * 9 avr. 2010  
33   */
34  public class JCRAPIAspectConfig
35  {
36  
37     /**
38      * The logger
39      */
40     private static final Log LOG = ExoLogger.getLogger(JCRAPIAspectConfig.class);
41  
42     /**
43      * The list of interfaces that we want to monitor
44      */
45     private Class<?>[] targetInterfaces;
46  
47     /**
48      * Default constructor
49      */
50     public JCRAPIAspectConfig(InitParams params)
51     {
52        this.targetInterfaces = loadTargetInterfaces(params.getValuesParam("targetInterfaces"));
53     }
54  
55     /**
56      * @return the list of interfaces to monitor
57      */
58     private Class<?>[] loadTargetInterfaces(ValuesParam params)
59     {
60        List<?> values = params.getValues();
61        List<Class<?>> lTargetInterfaces = new ArrayList<Class<?>>();
62        if (values != null)
63        {
64           for (Object o : params.getValues())
65           {
66              String className = null;
67              try
68              {
69                 className = (String)o;
70                 lTargetInterfaces.add(Class.forName(className));
71              }
72              catch (ClassNotFoundException e)
73              {
74                 LOG.warn("Cannot find the target interface " + className, e);
75              }
76           }
77        }
78        Class<?>[] targetInterfaces = new Class<?>[lTargetInterfaces.size()];
79        return (Class<?>[])lTargetInterfaces.toArray(targetInterfaces);
80     }
81     
82     /**
83      * @return the list of target interfaces
84      */
85     public Class<?>[] getTargetInterfaces()
86     {
87        return targetInterfaces;
88     }
89  }