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.Produce;
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 Produce} injection point
033 *
034 * @version $Revision: 18868 $
035 */
036 public class ProduceInjector extends CamelPostProcessorHelper implements AnnotationMemberProvider<Produce> {
037
038 @Inject
039 public ProduceInjector(CamelContext camelContext) {
040 super(camelContext);
041 }
042
043 public boolean isNullParameterAllowed(Produce produce, Method method, Class<?> aClass, int index) {
044 return false;
045 }
046
047 public Object provide(Produce inject, TypeLiteral<?> typeLiteral, Field field) {
048 Class<?> type = field.getType();
049 String injectionPointName = field.getName();
050 String endpointRef = inject.ref();
051 String uri = inject.uri();
052
053 return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
054 }
055
056 public Object provide(Produce inject, TypeLiteral<?> typeLiteral, Method method, Class<?> aClass, int index) {
057 Class<?>[] parameterTypes = method.getParameterTypes();
058 Class<?> type = parameterTypes[index];
059 String injectionPointName = ObjectHelper.getPropertyName(method);
060 String endpointRef = inject.ref();
061 String uri = inject.uri();
062
063 return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
064 }
065
066 }