/**
 * Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.cdi;

import org.apache.camel.spi.Registry;

import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Vetoed
final class CdiBeanRegistry implements Registry {

    private final BeanManager manager;

    CdiBeanRegistry(BeanManager manager) {
        this.manager = manager;
    }

    @Override
    public Object lookupByName(String name) {
        return BeanManagerHelper.getReferenceByName(manager, name, Object.class);
    }

    @Override
    public <T> T lookupByNameAndType(String name, Class<T> type) {
        return BeanManagerHelper.getReferenceByName(manager, name, type);
    }

    @Override
    public <T> Map<String, T> findByTypeWithName(Class<T> type) {
        Map<String, T> references = new HashMap<>();
        for (Bean<?> bean : manager.getBeans(type, AnyLiteral.INSTANCE))
            if (bean.getName() != null)
                references.put(bean.getName(), BeanManagerHelper.<T>getReference(manager, type, bean));

        return references;
    }

    @Override
    public <T> Set<T> findByType(Class<T> type) {
        return BeanManagerHelper.getReferencesByType(manager, type, AnyLiteral.INSTANCE);
    }

    @Override
    public Object lookup(String name) {
        return lookupByName(name);
    }

    @Override
    public <T> T lookup(String name, Class<T> type) {
        return lookupByNameAndType(name, type);
    }

    @Override
    public <T> Map<String, T> lookupByType(Class<T> type) {
        return findByTypeWithName(type);
    }

    @Override
    public String toString() {
        return "CDI bean registry";
    }
}

@@ -703,16 +703,116 @@
 egistry;
+%0Aimport org.apache.camel.util.ObjectHelper;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -1101,16 +1101,102 @@
 manager;
+%0A    private static final Logger LOG = LoggerFactory.getLogger(CdiBeanRegistry.class);
 %0A%0A    Cd
@@ -1323,32 +1323,134 @@
 (String name) %7B%0A
+        ObjectHelper.notEmpty(name, %22name%22);%0A        LOG.trace(%22Looking up bean with name %7B%7D%22, name);%0A
         return B
@@ -1595,32 +1595,195 @@
 lass%3CT%3E type) %7B%0A
+        ObjectHelper.notEmpty(name, %22name%22);%0A        ObjectHelper.notNull(type, %22type%22);%0A        LOG.trace(%22Looking up bean with name %7B%7D of type %7B%7D%22, name, type);%0A
         return B
@@ -1919,32 +1919,130 @@
 lass%3CT%3E type) %7B%0A
+        ObjectHelper.notNull(type, %22type%22);%0A%0A        LOG.trace(%22Lookups based of type %7B%7D%22, type);%0A
         Map%3CStri
@@ -2386,32 +2386,129 @@
 lass%3CT%3E type) %7B%0A
+        ObjectHelper.notNull(type, %22type%22);%0A        LOG.trace(%22Lookups based of type %7B%7D%22, type);%0A
         return B
@@ -2995,24 +2995,63 @@
 n %22C
-DI b
+di B
 ean 
-r
+R
 egistry
+%5B%22 + System.identityHashCode(this) + %22%5D
 %22;%0A 

Add logging TRACE