/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.script.internal.service;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.script.service.ScriptService;
import org.xwiki.script.service.ScriptServiceManager;

/**
 * Locate Script Services by name dynamically at runtime by looking them up agains the Component Manager.
 * 
 * @version $Id$
 * @since 2.3M1
 */
@Component
@Singleton
public class DefaultScriptServiceManager implements ScriptServiceManager
{
    /**
     * Used to locate Script Services dynamically. Note that since the lookup is done dynamically new Script Services
     * can be added on the fly in the classloader and they'll be found (after they've been registered against the
     * component manager obviously).
     */
    @Inject
    @Named("context")
    private Provider<ComponentManager> componentManager;

    /**
     * The logger to log.
     */
    @Inject
    private Logger logger;

    @Override
    public ScriptService get(String serviceName)
    {
        ScriptService scriptService;

        try {
            scriptService = this.componentManager.get().getInstance(ScriptService.class, serviceName);
        } catch (Exception e) {
            this.logger.debug("Failed to lookup script service for role hint [{}]", serviceName, e);

            scriptService = null;
        }

        return scriptService;
    }
}

@@ -2088,19 +2088,120 @@
 tService
+ = null
 ;%0A%0A
+        if (this.componentManager.get().hasComponent(ScriptService.class, serviceName)) %7B%0A    
         
@@ -2206,16 +2206,20 @@
   try %7B%0A
+    
         
@@ -2321,16 +2321,20 @@
         
+    
 %7D catch 
@@ -2361,16 +2361,20 @@
         
+  
+  
 this.log
@@ -2381,13 +2381,13 @@
 ger.
-debug
+error
 (%22Fa
@@ -2454,17 +2454,16 @@
 me, e);%0A
-%0A
         
@@ -2465,37 +2465,128 @@
         
+ %7D%0A        %7D else %7B%0A            this.logger.debug(%22No
  script
-S
+ s
 ervice 
-= null
+registred for role hint %5B%7B%7D%5D%22, serviceName)
 ;%0A      

Improve log