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 */
017package org.apache.camel.component.bean;
018
019import java.lang.annotation.Annotation;
020import java.util.Arrays;
021
022import org.apache.camel.Expression;
023
024/**
025 * Parameter information to be used for method invocation.
026 *
027 * @version 
028 */
029public class ParameterInfo {
030    private final int index;
031    private final Class<?> type;
032    private final Annotation[] annotations;
033    private Expression expression;
034
035    public ParameterInfo(int index, Class<?> type, Annotation[] annotations, Expression expression) {
036        this.index = index;
037        this.type = type;
038        this.annotations = annotations;
039        this.expression = expression;
040    }
041
042    public Annotation[] getAnnotations() {
043        return annotations;
044    }
045
046    public Expression getExpression() {
047        return expression;
048    }
049
050    public int getIndex() {
051        return index;
052    }
053
054    public Class<?> getType() {
055        return type;
056    }
057
058    public void setExpression(Expression expression) {
059        this.expression = expression;
060    }
061
062    public <T extends Annotation> T hasAnnotation(T type) {
063        if (annotations == null) {
064            return null;
065        }
066        for (Annotation ann : annotations) {
067            if (ann.annotationType().isAssignableFrom(type.annotationType())) {
068                return (T) ann;
069            }
070        }
071        return null;
072    }
073
074    @Override
075    public String toString() {
076        final StringBuilder sb = new StringBuilder();
077        sb.append("ParameterInfo");
078        sb.append("[index=").append(index);
079        sb.append(", type=").append(type);
080        sb.append(", annotations=").append(annotations == null ? "null" : Arrays.asList(annotations).toString());
081        sb.append(", expression=").append(expression);
082        sb.append(']');
083        return sb.toString();
084    }
085}