001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.guice.impl;
018
019 import java.lang.reflect.Field;
020 import java.lang.reflect.Method;
021
022 import com.google.inject.Inject;
023 import com.google.inject.TypeLiteral;
024
025 import org.apache.camel.CamelContext;
026 import org.apache.camel.EndpointInject;
027 import org.apache.camel.impl.CamelPostProcessorHelper;
028 import org.apache.camel.util.ObjectHelper;
029 import org.guiceyfruit.support.AnnotationMemberProvider;
030
031 /**
032 * Injects values into the {@link EndpointInject} injection point
033 *
034 * @version $Revision: 18868 $
035 */
036 public class EndpointInjector extends CamelPostProcessorHelper implements
037 AnnotationMemberProvider<EndpointInject> {
038
039 @Inject
040 public EndpointInjector(CamelContext camelContext) {
041 super(camelContext);
042 }
043
044 public Object provide(EndpointInject inject, TypeLiteral<?> typeLiteral, Field field) {
045 Class<?> type = field.getType();
046 String injectionPointName = field.getName();
047 String uri = inject.uri();
048 String endpointRef = inject.ref();
049
050 return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
051 }
052
053 public Object provide(EndpointInject inject, TypeLiteral<?> typeLiteral, Method method, Class<?> aClass, int index) {
054 Class<?>[] parameterTypes = method.getParameterTypes();
055 Class<?> type = parameterTypes[index];
056 String injectionPointName = ObjectHelper.getPropertyName(method);
057 String endpointRef = inject.ref();
058 String uri = inject.uri();
059
060 return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
061 }
062
063 public boolean isNullParameterAllowed(EndpointInject endpointInject, Method method, Class<?> aClass, int index) {
064 return false;
065 }
066
067 }